← All writing
Engineering

Sub-100ms tracking with an event-driven backbone

Why an append-only log beat polling for a pan-India operator managing 18,000+ daily shipments.

Eigensu Engineering5 min read

The brief was to make shipment tracking faster. The actual problem was that six different systems each held a partial, differently-stale view of where a parcel was, and every one of them found out by asking.

Polling is a tax you pay per consumer

With polling, adding a seventh consumer of shipment state adds a seventh load pattern on the source database. Freshness and cost move in opposite directions: to halve the staleness you double the queries. Nobody ever wins that negotiation, so in practice the interval gets set once and then defended for years.

18k+
Shipments tracked daily
90s → 80ms
Position staleness, p95
−64%
Read load on the source database

One log, many readers

Inverting it is conceptually simple: the scanner, the driver app and the depot terminal write events; everything else reads the log at whatever pace it needs. Consumers become independent, and adding the seventh one costs the source system nothing.

shipment-events.ts
// One event type per real-world thing that happened.type ShipmentEvent =  | { kind: "scanned";   at: Timestamp; hub: HubId;    awb: string }  | { kind: "loaded";    at: Timestamp; vehicle: Id;   awb: string }  | { kind: "departed";  at: Timestamp; vehicle: Id;   awb: string }  | { kind: "delivered"; at: Timestamp; pod: PodRef;   awb: string }; // Consumers project the log into whatever shape they need.//   tracking-api  → latest position per AWB      (keyed, compacted)//   ops-console   → live exceptions              (windowed, 15m)//   billing       → completed legs               (batch, nightly)

The discipline that makes this work is that events describe what happened, never what should happen next. A scan is a fact. "Notify the customer" is a decision, and decisions belong to consumers. Otherwise the log becomes a queue of instructions and you have rebuilt the coupling you were trying to remove.

Events are facts about the past. The moment one contains an instruction, you have a distributed monolith with extra steps.

What we would do differently

  • Version the event schema from day one. We added versioning in month four and paid for it twice.
  • Decide the retention and replay story before the first consumer, not after the first incident that needs a replay.
  • Keep the projections genuinely disposable. If rebuilding one takes longer than a lunch break, it will not get rebuilt when it should be.

None of this required exotic infrastructure. It required agreeing, once, that the log is the source of truth and that everything else is a view of it.

Written by
Eigensu Engineering
← Back to all writing
Get started

Rather have us fix it than read about it?

Tell us which process is eating the most hours. We'll map it, scope it, and show you what the automated version looks like.

Start a project