Dispatch matching rewrite
Freightline · 2025 · Go, Postgres, Redis
Matching drivers to loads ran as a single Postgres query with eleven joins, and it had grown a 1.4 second p99 during morning peak. Dispatch staff had started refreshing the page to force a retry, which doubled the load that was already the problem.
I split the read path off, precomputed eligibility per driver on a five second cycle, and moved the final ranking into the application where it could short-circuit. The query kept its correctness guarantees: a driver who becomes ineligible mid-cycle is filtered at assignment, not at ranking.
- p99 latency
- 1.4s → 180ms
- Timeouts
- -94%
- Database spend
- $6.2k → $2.8kper month
- Rollout
- 3 weeksbehind a flag