How to Reduce API Latency: Caching, Queries, and Edge Patterns


Caching strategies, database query optimisation, and edge patterns that reduce wait time on high-traffic API endpoints — measured with traces, not guesswork.
Measure before you rewrite
The client came to us with a dashboard API sitting at roughly 1.2s p95. Stakeholders wanted a rewrite. We started with traces instead. OpenTelemetry showed three dominant costs: an N+1 ORM pattern, a synchronous enrichment call to a partner API, and zero caching on mostly-static catalog data.
That triage mattered. Rewrites feel productive; eliminating unnecessary work is usually faster. We set a success metric — p95 under 250ms for the authenticated read path — and refused to celebrate micro-optimisations that did not move that number.
Publish the p95 target next to the endpoint in the service README. Teams optimise what is visible; invisible budgets get ignored.
Query shapes and indexes that match access
The N+1 vanished after we introduced a single SQL query with targeted joins and a covering index for the filter set the UI actually used. EXPLAIN plans before and after became part of the PR template for this service.
We also stopped selecting wide rows for list endpoints. Returning only the columns the card UI needed cut I/O and serialisation time more than any JSON compressor ever did.
Publish the p95 target next to the endpoint in the service README. Teams optimise what is visible; invisible budgets get ignored.
Caching with explicit invalidation
Redis cached catalog and permission snapshots with short TTLs plus event-driven invalidation on writes. The mistake teams make is caching without a coherence story — we documented every cache key, owner, and bust path.
For personalised payloads, we cached partial fragments and assembled at the edge of the API. Full-response caching looked simpler but collapsed under permission variance across tenants.
Publish the p95 target next to the endpoint in the service README. Teams optimise what is visible; invisible budgets get ignored.
Edge and async where it counts
Partner enrichment moved behind an async job with a stale-while-revalidate response for the dashboard shell. Users saw useful data immediately; enrichment caught up within seconds.
Read-heavy geo traffic benefited from edge caching of public fragments. Authenticated mutations stayed regional. Large latency wins rarely come from one trick — they come from removing wait time the product never needed on the critical path.
Publish the p95 target next to the endpoint in the service README. Teams optimise what is visible; invisible budgets get ignored.
Protect the win with budgets
After a latency win, add p95 budgets to CI or release checks for the critical endpoint. Without a guardrail, the next feature quietly reintroduces N+1 queries and synchronous partner calls.
Trace-led optimisation plus an explicit budget is how API performance stays a product property instead of a one-off hero project.
Publish the p95 target next to the endpoint in the service README. Teams optimise what is visible; invisible budgets get ignored.
Kill N+1 queries with shapes the UI actually needs
List endpoints should return only the columns the card UI needs. Prefer a single SQL query with targeted joins and a covering index for the filters users actually apply. Put EXPLAIN plans in the PR template for hot paths.
Wide ORM selects and per-row enrichment calls are the usual villains behind 1s dashboards. Measure them with traces before rewriting the service.
Publish the p95 target next to the endpoint in the service README. Teams optimise what is visible; invisible budgets get ignored.
Cache with an owner and a bust path
Redis helps only when every cache key has an owner, TTL, and invalidation story. Cache catalog and permission snapshots; assemble personalised payloads from fragments instead of caching full responses that vary by role.
Document keys next to the write paths that bust them. Caching without coherence is how tenants see each other’s stale data or never see updates.
Publish the p95 target next to the endpoint in the service README. Teams optimise what is visible; invisible budgets get ignored.
Move partner calls off the critical path
If a third-party enrichment is not required to render the first useful pixel, make it async with stale-while-revalidate. Users should see the shell immediately; enrichment can catch up seconds later.
That pattern, plus edge caching of public fragments, is how we repeatedly cut API latency without heroic rewrites.
Publish the p95 target next to the endpoint in the service README. Teams optimise what is visible; invisible budgets get ignored.
“Sustainable delivery comes from making the important trade-offs explicit, measurable, and recoverable.”
Checklist
- User-facing SLO and baseline captured
- Critical path traced end to end
- Data and dependency ownership documented
- Degraded behavior covered by tests
- Rollout and rollback plan reviewed
- Regression signal monitored after release

Umar Khalid
Software Engineering Manager
Manages day-to-day software engineering across APIs, web UI, and AI features — focused on reliable, maintainable production systems clients can own.
Let's build something
remarkable
Whether you need a web or mobile app with AI integrations, blockchain work, or a conversation about our AI products — tell us what you're building and we'll respond fast.
Blog questions
How we write, how often we publish, and how you can contribute or stay in the loop.
Blogs are written by Automative Tech’s engineering leadership — Muhammad Talha Zubair, Bilal Hassan, and Umar Khalid — based on production web, mobile, AI integration, and blockchain work.
We lead with custom web and mobile delivery with AI integrations — Next.js, React, React Native, Flutter, and LLM features. Selected posts also cover blockchain, AI products, and cloud when they support shipping real products.
A few deep pieces per month. We prioritize substance over cadence.
Yes with attribution and a link back to the original. For syndication, contact us for a simple agreement.
Occasionally, when the author has real production experience. Pitch a short outline via the contact form.
Follow the social links in the footer, or contact us to ask about engineering notes updates.


