How to Scale High‑Concurrency Write Operations with Asynchronous Patterns

This article examines a high‑traffic video‑watching scenario, identifies database write bottlenecks, and presents four asynchronous solutions—thread‑pool, in‑memory queue with scheduled tasks, message‑queue, and Agent‑plus‑MQ—detailing their implementation steps, trade‑offs, and best‑practice guidelines.

dbaplus Community
dbaplus Community
dbaplus Community
How to Scale High‑Concurrency Write Operations with Asynchronous Patterns

1. Business Scenario

In a teaching platform, teachers log in, view a list of courses, and watch course videos. The front end fetches video metadata from a Redis cache, while the back end records each watch event in a MySQL table. As concurrent users increase, write requests grow exponentially, causing thread blockage and slow responses.

2. Thread‑Pool Mode

Inspired by a previous experience with a high‑traffic red‑packet system, the write operation was off‑loaded to an independent thread pool. The controller returns immediately, while the pool asynchronously executes the activation logic, stabilizing the service without timeouts.

Key considerations for this mode:

Do not set the thread count too high to avoid exhausting database connections.

Size the thread‑pool queue appropriately to prevent memory overflow.

3. Local Memory + Scheduled Task

The open‑source community’s view‑count solution stores incoming events in an in‑memory LinkedBlockingQueue. A background thread wakes every minute, batches the queued items into a List, and executes Jdbc.batchUpdate to write them to the database.

This approach requires no changes to the existing business logic, offers high throughput, and keeps latency low, but it introduces the risk of memory overflow if the queue grows unchecked.

4. MQ Mode

Message queues provide asynchronous processing and decoupling. The workflow is:

Controller receives the write request and converts the watch record into a message.

The teaching service publishes the message to the MQ.

A consumer service pulls messages from the MQ and performs batch database writes.

Advantages include high availability, efficient asynchronous delivery, and built‑in persistence. The downside is the added operational complexity of managing an extra component.

5. Agent Service + MQ Mode

An independent Agent process runs on the teaching server. After the service receives a write request, it writes the request payload (e.g., JSON) to a local file and immediately returns success to the front end.

The Agent watches the file, streams new entries to the MQ, and a consumer later persists them to MySQL. This architecture keeps the business service free of MQ dependencies while still gaining asynchronous durability.

6. Summary

Asynchronous processing is valuable when write‑heavy operations consume excessive resources and can tolerate slight delays. Four practical patterns—thread‑pool, in‑memory queue with scheduled batch, pure MQ, and Agent‑plus‑MQ—share the core idea of queuing write commands, responding instantly to the client, and letting a background worker handle persistence. Choose the pattern that balances performance, complexity, and reliability for your specific load.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Batch ProcessingAsynchronoushigh concurrencythread poolbackend optimization
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.