Large-Scale Concurrency Control: Solving the DB Bottleneck from a Flood of “Likes”

CK CK 3788 
Created at
Updated at  
269 0 0

1. The Problem: Hotspots Created by Viral Posts

A service that ran perfectly fine on most days would slow to a crawl — and sometimes the database would freeze entirely — the moment traffic converged on a single influencer’s post or an event-driven piece of content. The root cause was write contention on a single row.

When the likes count is updated directly on a column of the post’s row, every single “like” request for that post lines up for the same row lock. As concurrent requests grow, lock wait times climb, the connection pool drains, and eventually even unrelated requests get dragged down.

Imagine it’s a quiet Tuesday afternoon. Our system is humming along perfectly, and the servers are running cool.

Suddenly, an influencer with five million followers hits "Publish" on our platform.

Within seconds, thousands of people open the app, read the post, and start smashing that "Like" button. It looks like a massive win for user engagement, right? But down in the engine room, a disaster is brewing.

Large-Scale Concurrency Control: Solving the DB Bottleneck from a Flood of “Likes”

 

The Problematic Architecture

Large-Scale Concurrency Control: Solving the DB Bottleneck from a Flood of “Likes”

 

Bottleneck Summary

SymptomRoot Cause
Spiking response latencySerialized write locks on the same row
Connection pool exhaustionConnections held hostage by lock waits
Cascading failureOne hot post’s load spreads across the whole DB
Write ceilingSingle-row update throughput becomes the system limit

 

 

2. The Strategy: Eliminate Direct Writes — Distribute and Decouple Them

The solution rests on three core ideas.

  1. Don’t write to the DB immediately — accept requests first in a fast in-memory store (Redis).
  2. Batch the writes — instead of applying each request one by one, aggregate them and apply them periodically in bulk.
  3. Persist asynchronously — decouple DB writes from the user’s response path via a message queue.

The improved architecture is described below in three modes.


 

3. Improved Architecture — Mode 1: Simplified View

The whole flow at a glance. For non-technical stakeholders or a high-level overview.

Large-Scale Concurrency Control: Solving the DB Bottleneck from a Flood of “Likes”

One-line summary: A fast store accepts user requests and responds instantly, while the actual DB updates are batched and applied behind the scenes.


 

4. Improved Architecture — Mode 2: Reference View

Structurally represents each component’s role and the data flow. For design reviews and documentation.

Large-Scale Concurrency Control: Solving the DB Bottleneck from a Flood of “Likes”

PRO

Responsibilities by Layer

LayerRole
ApplicationStateless API servers; absorb traffic via horizontal scaling
Fast WriteRedis absorbs writes instantly; atomic counting via INCR
AsyncQueue + worker decouple DB writes into async, batched operations
PersistenceThe DB receives only aggregated results, not individual requests


 

5. Improved Architecture — Mode 3: Technical View

Detailed from an implementation standpoint: key design, atomic operations, idempotency, and batch flush. For engineers building it.

Large-Scale Concurrency Control: Solving the DB Bottleneck from a Flood of “Likes”

PRO

Implementation Notes

Idempotency SADD’s return value prevents duplicate “likes.” If a user has already liked the post, it returns 0 and the count does not increment — so retries from network failures or double-clicks are safe.

Atomicity Redis operations like INCR/SADD are atomic by virtue of its single-threaded execution model, so no locks are needed. The RDBMS row-lock contention itself disappears.

Eliminating Write Amplification (Batching) Instead of hitting the DB on every like, only changed posts are tracked in the dirty:posts set and flushed in bulk every N seconds. 100,000 likes collapse into a single +100000 update.

Load Isolation The DB write path is fully separated from the user’s response path, so a hot post’s load no longer propagates to other requests.


 

6. Before vs. After

AspectBefore (Direct Write)After (Redis + Batching)
Write contentionSerialized single-row locksLock-free atomic INCR
DB write count1 per like1 per N seconds (aggregated)
User responseBound to lock waitsInstant response (lower p99)
Duplicate handlingRequires separate lookupAuto-idempotent via SADD
Failure isolationLoad propagatesWrite path is isolated
ScalabilityDB limit = system limitHorizontally scalable


 

7. Trade-offs — Nothing Is Free

This design embraces eventual consistency. Right after a user hits “like,” it may not be instantly reflected on another user’s screen (typically within a few seconds). There’s also a risk of data loss before a flush if Redis fails, so safeguards like Redis persistence (AOF), early publishing to the queue, or a reconciliation batch are necessary.

In short, the core is a trade-off where we give up a little “real-time accuracy” to gain a great deal of “write throughput and stability.” It fits especially well for counters that tolerate slight delays, such as likes, view counts, and reaction totals.

 

This post outlines general large-scale concurrency-control patterns. Real-world application requires tuning to your specific traffic characteristics, consistency requirements, and infrastructure environment.

Tags Asynchronous Processing Batch Processing Concurrency Control Database Optimization Eventual Consistency High Throughput Hotspot Mitigation Redis Redis Caching Software Architecture System Scalability Write Contention Facebook X
Comments 0
Similar posts
  1. Batch processing composed of job manager, job store and worker based on AWS
    10,446
  2. Optimize the performance of a search results page that experiences high traffic
    139
  3. Temporal Programming Model - Robust, Long-Running, Fault-Tolerant Applications as WorkFlows
    349
  4. Real-Time Inventory & WMS System Design
    240
  5. Enterprise-Scale 100k+ TPS Order Tracking System Architecture
    198
  6. Scaling Sharded Databases: Taming Hot Shards with Dynamic Rebalancing
    547
  7. Observer Pattern
    2,389
  8. Using Queue Algorithm with Redis - RPUSH and LPOP
    767
  9. The Ultimate Data Engineering Roadmap
    1,069
  10. Upgrading PHP 7.4 to PHP 8.1 in CentOS 7
    642
  11. Coding Revolution with Claude Code & MoAI ADK(Agent Development Kit)
    726
  12. The Blueprint of Success: Why System Design and Architecture Matter?
    395
  13. Redis vs Memcached: Why Enterprise Tech Giants Choose Redis
    247
  14. System Requirements and Architecture: Intelligent Priority-Based Scheduler
    161
  15. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    229
  16. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    86
  1. The Ultimate Data Engineering Roadmap
    1,069
  2. Nine Types of Testing while we develop APIs
    511
  3. Apache Kafka - a distributed, fault-tolerant, high-throughput streaming platform
    613
  4. Comprehensive Software Development Flow : How Companies Ship Code To Production
    2,309
  5. DeepSeek v3 offers of ChatGPT's performance at 1/10 the price!
    633
  6. Difference between CPU and GPU - Why GPU is faster than CPU?
    802
  7. gRPC - Open-source Universal RPC Framework developed by Google
    766
  8. Exploring the Depths of Data Transfer: sendfile vs. kTLS
    1,317
  9. How Netflix Ensures Smooth Streaming with Open Connect CDN
    2,127
  10. Public DNS (Domain Name Service) based on IPv4, IPv6 widely used
    1,240
  11. All Engineering Software Development How can you prioritize software design trade-offs when developing a new product?
    1,339
  12. MR(Mixed Reality) Game Programming based on Unity 3D
    1,353
  13. Temporal Programming Model - Robust, Long-Running, Fault-Tolerant Applications as WorkFlows
    349
  14. Cadence Programming Model - A Distributed, Fault-Tolerant, Stateful Workflow Orchestration Framework
    285
  15. Multi-AZ Kafka Architecture
    141
  16. Hybrid Methods for Recommendation Service
    213
  17. Model-Based CF: Matrix Factorization for Recommendation Service
    177
  18. Memory-Based Collaborative Filtering for Recommendation Service
    186
  19. Content-Based Filtering for Recommendation Service (aka User-based Model)
    187
  20. Stateful Databases: A Deep Dive with Cassandra & TiDB
    186
  21. Why Kubernetes? Core Features and Microservice Orchestration Strategies
    569
  22. Quiz : Twice counter
    700
  23. Kubernetes, aka K8s, is an open-source container orchestration platform
    539
  24. Architecting for Resilience: AWS High Availability Components Including API Gateway
    133
  25. Is AWS API Gateway Disaster-Proof? DR, Benefits, and Multi-AZ Architecture Explained
    140
  26. FNC(Photo/Video File Name Changer) v1.1 Release - Date Time Bug Fix & Retry Function Added
    703
  27. Smart TV Cycling Apps – TV for Fitness
    807
  28. The public could reduce server cost, and enhance performance for global service distribution
    10,740
  29. Cloud gaming coming to Samsung Smart TVs
    556
  30. Kids App – Kids Learn While Parents Control on Samsung Smart TV
    761
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    27
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    24
  3. How do I create animated background for Google Meet?
    19,729
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    217
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    86
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    153
  7. Array of arguments passed to script in PHP
    85
  8. Invalid Auction Storms in Ad Tech
    93
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    198
  10. The Two Clocks of Ad Server Architecture
    63
  11. Frequency Cap Architecture Overview
    509
  12. Collecting Proof-of-Play from 100,000 Screens
    141
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    280
  14. What is RedisVL?
    105
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    224
  16. TPU & GPU Cluster Management Tools
    234
  17. The Concept of Scaffolding in AI Agents
    222
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    576
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    253
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    328
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    197
  22. Machine Learning: Training vs. Ranking
    213
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    217
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    189
  25. Designing a Data Curation System Around a Vector Database
    215
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    229
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    649
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    185
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    207
  30. Understanding Data Lineage
    252