Key Takeaways

- Datadog migrated a critical production system from FoundationDB to PostgreSQL using Claude and Cursor for test-driven refactoring
- Operations dropped from 45 minutes to about one second, with database costs reduced by 90%
- The success hinged on a strong test suite that served as a pass/fail criterion for every AI-generated change
Datadog's metrics pipeline had a problem. Their Stream Router API, built on an eventually consistent key-value store, was hitting transaction size limits. The worst operations took 45 minutes because of thousands of sequential database round trips. Engineers Arnold Wakim and team decided to migrate to PostgreSQL, and they used Claude and Cursor to do the heavy lifting.
The results: operations that once took 45 minutes now complete in about a second. Latencies dropped from hundreds of milliseconds to single digits. Storage shrank by up to 40x. Database costs fell 90%.
Why the original system broke down
Stream Router manages routing for Datadog's metrics pipeline. The original version used a key-value model that forced application code to reconstruct relationships between domain entities. The system would pull tens of thousands of entries into pod processes and essentially run relational database logic in-process, handling what foreign keys would normally enforce.
As the routing table grew, the KV database started hitting transaction size limits. The architecture couldn't scale. Datadog's engineers redesigned the schema to use PostgreSQL with proper foreign keys, replacing logic that previously lived in application code.
How Claude and Cursor fit into the refactoring process
The schema redesign was straightforward. Refactoring the entire codebase to use it was not. Wakim's team turned to AI, but not in the way you might expect. They didn't hand Claude autonomy over the codebase. Instead, they ran a systematic, test-driven process.
“We used Claude and Cursor to accelerate a systematic, test-driven refactoring process. They weren't generating code autonomously: For each method, we provided the old implementation, the new schema, and a failing test. The models would generate a first pass, and the tests told us whether it was correct.”
— Arnold Wakim, Datadog Engineer
Three elements made this work. First, strong code modularity. The new Stream Router implemented the same API on PostgreSQL, so nothing else in the system needed changes. Second, a comprehensive test suite that gave clear pass/fail criteria for every AI-generated change. Third, parallel infrastructure where two independent Stream Router instances ran side by side, handling the same requests while clients were routed between them via feature flags.
The three-phase migration
Phase one: Use Claude to describe the intent of each key function. This created a semantic map of what the code was supposed to do, separate from how it did it.
Phase two: Craft focused prompts to fix failing tests. Each prompt included the expected behavior plus context from phase one. Claude generated code, tests validated it, engineers reviewed the output.
Phase three: Deploy using a blue/green approach. The new PostgreSQL-backed Stream Router and the existing FoundationDB version ran in parallel. A dedicated validator service compared routing responses between them, alerting the team immediately if anything diverged.
Where AI fell short
Wakim was candid about the limitations. Higher-level prompts didn't work well. Claude generated correct but suboptimal queries, issuing far more database round trips than necessary.
Niche optimizations like batching, UNNEST tricks, and common table expressions required human input. Once engineers wrote the optimized versions, Claude could replicate the patterns in subsequent methods. But it didn't discover these patterns independently, even though they exist in the literature.
Token consumption was another issue. The team fed Claude full test output dumps instead of trimmed excerpts, and the iterative loop of test output, code context, and schema information burned through tokens quickly.
Logicity's Take
The real lesson here isn't that AI can migrate production systems. It's that AI-assisted refactoring only works when you've already done the hard engineering work: modular code, comprehensive tests, and parallel infrastructure for validation. Teams considering similar approaches should also look at tools like GitHub Copilot and Amazon CodeWhisperer, which offer different context window sizes and pricing models. Cursor's appeal is tight IDE integration with Claude, but the choice depends on existing toolchains and budget. The pattern Datadog established, AI generates, tests validate, humans optimize, is likely the template for production-grade AI-assisted development for the next few years.
What other teams can take from this
Wakim's conclusion is direct: the strength of their test suite determined how much they could trust AI-generated code. Without that safety net, the migration would have been far riskier and slower.
The approach also required accepting AI's limitations upfront. Claude accelerated the grunt work but couldn't handle performance optimization. Engineers still had to teach it patterns, then watch it replicate them. That's not autonomy. It's a faster feedback loop.
For teams running similar migrations, the takeaway is clear: invest in tests first, keep prompts focused, and don't expect AI to optimize what it doesn't understand. The 90% cost reduction came from good engineering enabled by AI, not AI replacing engineering.
Frequently Asked Questions
What tools did Datadog use for their AI-assisted migration?
Datadog engineers used Claude (Anthropic's AI model) and Cursor (an AI-powered IDE) for test-driven refactoring of their Stream Router API.
How much did Datadog reduce database costs after the migration?
Database costs dropped by 90%, with storage becoming up to 40x smaller and operations that took 45 minutes completing in about one second.
Did Claude generate production-ready code automatically?
No. Claude generated first-pass code that had to pass existing tests. Engineers reviewed all output and manually wrote optimizations like batching and common table expressions.
What was the key factor that made Datadog's AI migration successful?
A comprehensive test suite that served as clear pass/fail criteria for every AI-generated change, allowing engineers to trust the output without manual verification of correctness.
Can this approach work for teams without extensive test coverage?
The approach depends heavily on test coverage. Without a strong test suite, there's no reliable way to validate AI-generated code, making the migration far riskier.
Need Help Implementing This?
If you're planning a production migration and want to apply AI-assisted refactoring, start by auditing your test coverage. Reach out to the Logicity team for guidance on test-driven AI development workflows tailored to your stack.
Source: InfoQ
Huma Shazia
Senior AI & Tech Writer
Produced with AI assistance and reviewed by the Logicity editorial team. Learn more in our Editorial Policy.
Related Articles
Browse all
GitHub Copilot CLI: What Business Leaders Need to Know
GitHub's AI-powered command line interface is changing how developers work, with early adopters reporting significant productivity gains. Here's what decision-makers should understand about this tool's business impact and whether it's worth the investment for your engineering team.

URGENCY: IT-Tools Revolutionizes Development with Unified Platform - The New Stack
IT-Tools is changing the game for developers by bringing numerous useful tools into one convenient location. According to The New Stack, this platform is a must-have for any development team. We dive into the details of what makes IT-Tools so special and how it can benefit your workflow.

SURPRISING TAKE: Why Agentic Coding Is Not a Threat But a Catalyst for Developer Growth
The coding landscape is evolving with agentic coding, a shift that's both exciting and intimidating for many developers. We explore why embracing this change can lead to unprecedented growth and innovation. By understanding the core of agentic coding, developers can position themselves at the forefront of the tech revolution.

SURPRISING TAKE: Experienced Open-Source Developers Are Not As Productive With Early-2025 AI As You Think
We dive into the impact of early-2025 AI on experienced open-source developer productivity, exploring the challenges and opportunities that come with AI adoption. According to McKinsey, AI can increase productivity by up to 40%, but is this true for experienced open-source developers? We examine the data and expert insights to find out.


