Real-time bidding gives you well under 100ms to answer or you don't take part in the auction. Here is where the time went on an ad platform answering in ~340ms and the changes that brought it under 60ms at peak.
Most latency targets are aspirations. In real-time bidding they are a hard cutoff. An exchange sends a bid request, waits a fixed window and runs the auction with whatever answers arrived. A bid that lands late isn't a slow bid. It isn't a bid at all and the impression goes to someone else.
When we took on full-stack engineering for act.ad, the platform needed to grow from tens of thousands of ad requests a day to millions while staying inside a sub-100ms response window. At the start, responses at peak load were around 340ms. Today the platform sustains 3-4 million requests a day with p95 bid responses under 80ms.
None of the changes were exotic. Most of them came down to one question asked over and over: what is this request waiting for and does it have to?
Three things were slowing the request path down and only one of them looked like a bidding problem.
The third one is the instructive one. If reporting can slow down bidding, the two share a resource they shouldn't.
The single biggest structural change was to stop writing events synchronously. Events now go to a Redis Stream: an append is fast and doesn't wait on the database. A consumer group drains the stream in batches into PostgreSQL. A second consumer feeds ClickHouse, which answers the reporting queries.
That one change separated three workloads that had been fighting each other: answering bids, storing events and querying them. Reporting can now be as heavy as publishers need without touching bid latency.
The trade-off is that reporting becomes eventually consistent. A publisher's dashboard is seconds behind reality rather than exact to the request. For reporting that's the right trade. For anything that gates a bid, it isn't, which is why budgets are handled differently (below).
We rebuilt bidding as a stateless Koa service. Stateless means any instance can answer any request, so capacity scales by adding instances rather than by tuning one big process.
Node.js handles I/O concurrency well, but CPU-bound work blocks its event loop and a blocked event loop delays every other request on that process. Bid evaluation is CPU work: scoring eligible campaigns against the request. So it runs on worker threads, leaving the main thread free to accept and route requests.
Every auction request now goes through four steps:
The design rule behind it: everything a bid waits on should be in memory or computable on the spot. Redis also handles rate limiting, so abusive or misconfigured traffic is turned away cheaply, before it costs evaluation time.
A cache in front of budgets raises an obvious question: how stale can a budget be before you overspend? There is no universal answer. Decide how much potential overspend is acceptable, then set how budget state is refreshed to match that number, rather than reaching for strong consistency the bid window can't afford.
Average latency is the wrong number for an auction. If the average is 40ms and one request in twenty takes 150ms, then one bid in twenty never takes part and the average hides it completely. We track p95 because that's the share of auctions you're willing to lose to latency, said plainly.
The tail is also where contention shows up first. Reporting load, garbage-collection pauses and a busy event loop all show as tail spikes long before they move the mean.
We evaluated Kafka for the event queue and chose Redis Streams. At around 4 million events a day, the operational cost of running a Kafka cluster wasn't justified. Redis was already in the stack for bid caching, so streams added no new infrastructure to operate.
The design is deliberately ready for that migration: producers and consumers sit behind the same append-and-drain interface. If volume grows by an order of magnitude, swapping the transport is contained work rather than a rewrite.
Peak response time went from around 340ms to under 60ms. The platform sustains 3-4M requests a day at p95 under 80ms. Fill rate rose 14%, part of which we attribute to faster responses making the platform competitive in more auctions. That attribution is partial and we'd rather say so than claim all of it.
The lesson generalises beyond ad tech. When a system has a hard latency budget, list everything the request waits on, then move everything that doesn't have to happen now somewhere else.