Menu

How Does a Background Job Know the Database Is Busy?
πŸ“°

How Does a Background Job Know the Database Is Busy?

DEV Community: dotnetΒ·VasylΒ·about 8 hours ago
#h2dn8eIG
#devtodotnet#devto#dev#database#time
Long article (1661 words) β€” no AI summary yet.
Reading 0:00
15s threshold

Imagine Black Friday, 9 PM. Checkout gets slow. The p99 latency jumps from 80 ms to 4 seconds. Nobody deployed anything. No server is down.

The cause is a CSV export that someone in the back office started an hour ago. It reads the orders table as fast as it can. The database is not broken. It is just serving the wrong customer first.

How was the export supposed to know that it should step aside? That is what this post is about.

TL;DR: A background job and a checkout request use the same database. The request cannot wait. The job can. So the job checks the health of the database between batches and pauses when the database is busy. The usual signal is replication lag. If you cannot read that signal, measure the time of your own queries and adapt.

Why this post

I wrote a small GraphQL server to learn how bulk exports work. One line in the server stopped me:

while ( databaseLoad . Percent > 70 ) await Task .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.