How Datadog Used Claude and Cursor for Test-Driven Production Migration
Summary
Datadog engineer Arnold Wakim detailed the company's successful migration of its critical Stream Router API, which manages metrics pipeline routing, from a key-value (KV) model on FoundationDB to a relational schema on PostgreSQL. The original system faced severe performance issues, with operations taking up to 45 minutes due to transaction size limits. To refactor the codebase, Datadog utilized AI tools, specifically Claude and Cursor, in a test-driven process. These AI models generated initial code passes for methods, guided by the old implementation, new schema, and failing tests. Key enablers included strong code modularity, a comprehensive test suite, and a parallel "blue/green" infrastructure with a validator service. Post-migration, operations now complete in about one second, latencies are significantly reduced, data storage is 40x smaller, and database costs are down by 90%. While AI generated correct code, human input was needed for query optimization and to manage high token consumption.
Key takeaway
For Software Engineering teams considering AI-assisted refactoring for critical systems, prioritize developing a robust, comprehensive test suite before engaging AI tools. Your test suite will serve as the essential guardrail, validating AI-generated code and ensuring correctness during complex migrations. Be prepared to manually optimize AI-generated queries for performance and manage high token consumption, as AI may produce correct but inefficient solutions.
Key insights
The strength of a comprehensive test suite is paramount for safely and effectively integrating AI into critical code refactoring.
Principles
- Modular code simplifies backend migrations.
- Comprehensive tests validate AI-generated changes.
- Parallel infrastructure enables safe production shifts.
Method
Datadog's migration involved three phases: Claude describing function intent, focused prompts fixing failing tests with context, and blue/green deployment with continuous validation between parallel systems.
In practice
- Use AI for initial code passes, not autonomous generation.
- Provide AI with old code, new schema, and failing tests.
- Optimize AI-generated queries manually for efficiency.
Topics
- AI-assisted Refactoring
- Production Migration
- Claude
- Test-Driven Development
- Blue/Green Deployment
- PostgreSQL
Best for: AI Architect, CTO, VP of Engineering/Data, AI Engineer, Machine Learning Engineer, Software Engineer
Related on AIssential
See Counsel's argued verdicts on the open AI decisions leaders are weighing →
Editorial summary, takeaway, and curation by AIssential. Original article published by InfoQ.