Solving database contention with optimistic locking
Read Full ArticleSummary
The article explores the challenges of database contention in the context of the Duolingo app's notification system, which faced delays due to locking issues during high traffic. It details the implementation of optimistic locking as a solution, allowing transactions to proceed without immediate locks and checking for changes before committing. This approach significantly reduced database load and improved transaction speeds, demonstrating the effectiveness of optimistic locking in enhancing performance and resource efficiency.
Key Learnings
- 1Optimistic locking can reduce contention by allowing transactions to read data without locking, checking for changes before writing.
- 2Identifying and profiling transaction performance is crucial for understanding and mitigating locking issues in databases.
- 3Implementing a version ID for rows enables safe updates without overwriting concurrent changes.
- 4Thorough testing on mock databases is essential to ensure smooth transitions to new locking mechanisms without service interruptions.
- 5Monitoring failure modes and transaction retries helps in optimizing the system and preventing unnecessary load.
Who Should Read This
Senior Database Engineers implementing high-performance transaction systems in high-traffic applications
Test Your Knowledge
What are the trade-offs between optimistic locking and traditional locking mechanisms in terms of performance and complexity?
How does the introduction of a version ID impact the transaction flow and potential rollback scenarios?
What strategies can be implemented to minimize the occurrence of transaction retries in an optimistic locking system?
In what scenarios might optimistic locking lead to performance degradation, and how can these be mitigated?
Why is it important to monitor the failure modes of transactions in a system using optimistic locking?
Topics
More from Duolingo Engineering
View Duolingo engineering blogs →Automating Golden Path upgrades at scale: A journey from manual upgrades to an AI-powered workflow
The article outlines a project undertaken by the Engineering Studio team to automate the upgrade process of multiple Java services to adhere to a defined 'Golden Path' of technology standards. By...
Agentic Workflows: Scale AI Prompts Beyond Cursor—No Code Required
The article introduces 'agentic workflows' at Duolingo, designed to streamline the creation and deployment of AI-driven coding agents for routine tasks. These workflows enable users, including...
Building an AI Agent to Remove Feature Flags
The article outlines the creation of an AI agent designed to automate the removal of feature flags at Duolingo, leveraging Temporal for workflow orchestration and Codex CLI for AI-driven code...
2025 Duolingo Highlights: our biggest leaps in learning, play, and connection
In 2025, Duolingo made significant strides in enhancing its platform, introducing a variety of new features and courses aimed at improving user engagement and learning outcomes. Notably, the launch...
Dear Duolingo: How do I support someone who’s learning a language?
The article provides advice on how to support someone who is learning a new language. Dr. Emilie Zuniga offers five practical tips for being a supportive language-learning companion: allowing the...