Trace Tenant File Upload Failures via API Gateway
In this article
This guide walks through tracing tenant-specific file upload failures that occur behind an API gateway. It helps you isolate whether the problem lies in the client, the gateway, the backend service, or the storage layer, and provides a repeatable method to pinpoint the exact request and error. You’ll need access to the API gateway’s logs, the backend service logs, and ideally a way to reproduce the upload with a test file.
What You'll Need
- Access to API gateway logs (e.g., NGINX, Kong, AWS API Gateway, or similar)
- Access to backend application logs (where the upload is processed)
- Access to storage logs (S3, Azure Blob, or local disk) if applicable
- A test file and the tenant’s credentials or API key to reproduce the issue
- Correlation ID or request ID generation capability (if not already present)
- Basic command-line tools: curl, jq, grep, tail, and possibly a log aggregator (ELK, Splunk) if you have one
Step-by-Step
- Reproduce the failure with a controlled test. Use the tenant’s credentials or API key to upload a small, known file via the gateway. Note the exact time, file name, size, and the response status code. If you can’t reproduce, ask the tenant for their request ID or timestamp.
- Capture the request ID or correlation ID. Most gateways assign a unique ID to each request. Look for headers like
X-Request-ID,X-Correlation-ID, orX-Amzn-RequestId. If none exist, enable this in your gateway configuration going forward. - Search the gateway logs for that request ID. Filter logs by the tenant’s identifier (API key, username, or IP) and the time window. Look for the request line, response status, and any gateway-level errors (e.g., 413 Payload Too Large, 502 Bad Gateway, timeout).
- Check the gateway’s upload limits and timeouts. Verify the maximum allowed file size and request timeout. If the file is near the limit, try a smaller file to see if it succeeds. Adjust limits if needed, but confirm with your team first.
- Trace to the backend service. Search backend logs for the same request ID or the tenant’s session. Look for exceptions, stack traces, or error messages around the upload endpoint. Common issues: authentication failures, database connection errors, or disk full.
- Inspect storage logs. If the upload reaches storage, check if the file was written partially or not at all. Look for permission errors, bucket policy denials, or network issues between backend and storage.
- Analyze the response body. If the gateway returns an error, decode the response. Sometimes the backend sends a detailed error message that gets wrapped by the gateway. Use
curl -vor inspect the network tab in browser dev tools. - Check for tenant-specific configuration. Some tenants may have different quotas, rate limits, or storage paths. Verify the tenant’s settings in your database or config service.
- Review recent changes. If the failure started recently, check deployment logs for new gateway rules, backend updates, or storage policy changes that might affect this tenant.
- Document and escalate. If you cannot find the root cause, package the request ID, timestamps, and all relevant log excerpts into a ticket for the infrastructure team.
Common Mistakes
- Ignoring the request ID. Without a correlation ID, you’ll waste time searching by IP or user, which can be ambiguous.
- Only checking the gateway logs. The gateway often just forwards the error; the real cause is in the backend or storage.
- Assuming all tenants are the same. Tenant-specific quotas, IP allowlists, or custom headers can cause failures that don’t affect others.
- Forgetting about multipart parsing. If the backend fails to parse the multipart form, it may return a generic error. Check the backend’s file size limits and temporary directory permissions.
- Not checking the client side. Sometimes the client sends a malformed request or times out before the upload completes. Use a tool like Postman or curl to rule out client issues.
Tips
- Enable structured logging. Log JSON with fields for tenant ID, request ID, file size, and status. This makes filtering much easier.
- Set up a test tenant. Create a sandbox tenant with identical limits to reproduce issues without affecting production data.
- Use a file upload size that’s just below the limit. This helps detect off-by-one errors in gateway or backend limits.
- Monitor error rates per tenant. Set up dashboards that show upload success/failure rates by tenant to spot anomalies early.
- Keep a runbook. Document common failure modes and their fixes for quick reference.
Troubleshooting
If you can’t find the request in the gateway logs: The request may not have reached the gateway. Check the client’s network, DNS, or firewall. Also verify that the gateway’s access logs are enabled and that the timezone matches the client’s.
If the gateway returns a 413 but the file is within limits: The limit might be configured on a per-route or per-tenant basis. Check the gateway’s configuration for that specific route or tenant. Also, some gateways count the entire request body, including multipart overhead, so a file slightly under the limit may still exceed it.
If the backend times out: Look for slow database queries, antivirus scanning on upload, or a misconfigured reverse proxy. Increase the timeout temporarily to see if the upload eventually succeeds.
If the file uploads but the tenant reports failure: The client may be checking a different response than what the gateway sends. Verify the client’s success criteria (e.g., HTTP 200 vs 201) and check if the backend returns a success response but with a warning that the client treats as an error.
Frequently Asked Questions
How do I generate a correlation ID if my gateway doesn’t have one?
You can add a middleware or plugin that generates a UUID for each request and injects it as a header. Many gateways (like Kong or NGINX with Lua) support this natively.
What if the tenant’s file upload fails intermittently?
Intermittent failures often point to network instability, rate limiting, or resource exhaustion. Look for patterns: time of day, file size, or specific endpoints. Enable more verbose logging during the failure window.
Can I trace uploads without a request ID?
Yes, but it’s harder. Use the tenant’s username, IP address, and a narrow time window. Combine gateway and backend logs by matching timestamps and file sizes.
How do I check if the gateway is dropping the upload?
Look for gateway error logs that mention “client closed connection” or “upstream prematurely closed”. Also, use curl -v to see if the connection is reset before the backend responds.
What if the backend logs show no request at all?
That means the gateway never forwarded it. Check the gateway’s routing rules, ACLs, or rate limits. Also verify that the backend service is healthy and accepting connections.
Is it safe to increase the gateway’s upload limit?
Only after verifying that your backend and storage can handle larger files. Increasing the limit without checking memory and disk usage can crash services. Test in a staging environment first.