Service APIs & data layer
History query path — full scan timed out; index + light cache cut typical latency ~1–2s → ~50–100ms. Stale window ~2–3s accepted.
- Node.js
- TypeScript
- MongoDB
- Redis
- API design
Intro
IC role owning production Node.js APIs end to end. The sharp problem was user history queries — a full scan under real filters timed out. Indexing plus a light cache brought typical latency from ~1–2s to ~50–100ms, with an explicit trade-off that history could be stale by ~2–3s.
Architecture
- 01HTTP layerthin controllers
- 02Serviceshistory · domain logic
- 03Light cachehot history · ~2–3s stale OK
- 04Repositoriesindexed queries · migrations
- 05MongoDBsource of truth
What I did
- Owned the history API path end to end — query shape, indexes, light cache, and production behavior
- Replaced full-scan history reads with indexed access + light cache — typical latency ~1–2s → ~50–100ms
- Accepted and documented ~2–3s staleness on history so the hot path stayed fast
- Operated the services I shipped; this IC loop led into the next leadership role
Hard problems
History queries timing out on full scan
- Symptom
- User history endpoints timed out once real filters hit production data volume.
- Cause
- Query path scanned far more rows than needed — missing the index (and cache) the UI filter/sort actually required.
- Fix
- Added the right indexes and a light cache in front of hot history reads. Typical latency landed ~50–100ms (from ~1–2s). No other latency bands published — older detail is not recalled.
Freshness vs timeout on history
- Symptom
- Strictly fresh reads kept the path slow enough to miss SLAs users felt as “stuck loading.”
- Cause
- Hitting MongoDB on every history view fought the timeout; full consistency on that list was more expensive than the product needed.
- Fix
- Explicit stale window ~2–3s on cached history. Correct enough for the product; fast enough to stay interactive.
Problem
Users queried history; the naive full scan timed out under production filters. This was an IC delivery problem with a measurable read-path fix — not a platform redesign.
Trade-offs
- History may be stale ~2–3s — accepted so indexed + cached reads could hold ~50–100ms typical. Fresh-every-time was not worth the timeout risk on this surface.
Outcomes
Typical history latency ~1–2s → ~50–100ms after index + light cache. End-to-end ownership on the path I shipped. No additional public numbers — finer detail from that period is not available.