Users say one API endpoint has become slow in production. How do you find and fix the cause?
What the interviewer wants to hear
- Confirm with metrics: latency percentiles, error rate, when it started
- Use tracing to find which span is slow
- Check recent deploys, traffic and data growth
- Database analysis: slow query log, EXPLAIN ANALYZE, missing index, N+1
- Fix, verify with metrics, and add alerts or tests
Model answer
First I confirm the problem with metrics: look at p50, p95 and p99 latency for that endpoint, the error rate, and exactly when it started. Then I check what changed around that time: a deploy, a traffic spike, a big data import or a dependency slowdown. Next I use distributed tracing, such as OpenTelemetry with Jaeger or Datadog, to see which part of the request takes the time: database, an external API call or our own code. If it is the database, I check the slow query log and run EXPLAIN ANALYZE to find full scans, missing indexes, N+1 patterns or lock waits. If it is CPU, I profile. After fixing, for example adding an index or batching queries, I verify the latency graph has recovered and add an alert on p95 so we catch it earlier next time.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Backend Developer questions
- An API endpoint is slow because it runs a heavy database query. How would you add caching, and how do you keep the cache correct?
- You need to rename a column in a large production table that the live app uses. How do you do it without downtime?
- How do you change a public API without breaking existing clients, such as old mobile app versions?
- Sending emails and generating PDF invoices makes your checkout API slow. How would you move this work to the background?
- How would you add rate limiting to a public API that runs on many servers?
- You are asked to review the security of a REST API before launch. What would you check?
- Your service receives webhooks from a payment provider. How do you make handling them secure and reliable?
- When would you choose Kafka and when RabbitMQ for messaging between services?
- How would you design an API that lets users upload large files, such as videos of several gigabytes?