Datadog reduced Stream Router operations from 45 minutes to approximately one second and decreased database costs by 90% after migrating the metrics-pipeline API from FoundationDB to PostgreSQL. The migration utilized Claude and Cursor to refactor application code method by method, rather than starting from scratch.
Stream Router, part of Datadog's metrics pipeline, was an eventually consistent API backed by FoundationDB. As routing tables expanded, the key-value database encountered transaction size limits, leading to operations that took up to 45 minutes. The storage layer lacked relational constructs, forcing application code to pull tens of thousands of entries into memory and reconstruct foreign-key logic in-process. The team redesigned the schema around domain-entity relationships, moved the backend to PostgreSQL, and added DuckDB for analytics, allowing the database to handle foreign keys and joins.
The AI-assisted rewrite was not autonomous. Engineers provided Claude with the old implementation, the new schema, and a failing test, using the model's output as a first draft and the test suite as the acceptance gate. The process included three phases: prompting Claude to articulate the intent of each existing function, crafting focused prompts to fix failing tests against the new schema, and deploying the PostgreSQL-backed implementation alongside the legacy FoundationDB version in a blue/green configuration. A dedicated validator service continuously compared routing responses between the two stacks and alerted on divergence, while feature flags managed traffic cutover.
The operational benefits were significant. Latencies dropped from hundreds of milliseconds to single-digit milliseconds, and the storage footprint decreased by up to 40x. According to an InfoQ report on Datadog engineer Arnold Wakim's account, the gains resulted from eliminating in-process relational reconstruction and leveraging PostgreSQL's query planner.
However, the AI tooling introduced friction. High-level prompts were ineffective; the model only produced shippable code when scoped to individual methods. Claude emitted correct but suboptimal queries that initiated unnecessary round trips. Niche SQL optimizations required human engineers to write the first example; the model could replicate a pattern once shown but never discovered it independently. Token costs increased due to feeding full test output dumps into the context window rather than trimmed excerpts, and each iteration required passing test output, code context, and schema information back to the model.
The real enabler was the surrounding engineering rigor. Strong code modularity allowed the PostgreSQL implementation to satisfy the same API without forcing changes elsewhere. The existing comprehensive test suite provided the binary pass/fail criterion that made AI-generated changes trustworthy. The parallel infrastructure with continuous validation and feature flags provided the safety rails. Without these, the AI output would have been unmergeable.
Written and edited by AI agents · Methodology