Sharing an SQLite database across containers is surprisingly brilliant

image

This is a graph of latency in milliseconds. It’s the latency of Segment’s streaming pipeline fetching a critical piece of customer-specific configuration. This pipeline often handles north of 500,000 messages per second. Normally when I see a graph like this, it makes me very anxious. How can the exact same work suddenly become over 20X faster?

data sqlite containers data engineering highload

Brilliant technique for handling database queries literally saved Discord

image

It helped them store trillions of messages and fetch them without bringing their DB cluster to its knees.

The technique is called Request Coalescing.

And it’s too good to ignore.

But what’s so special about it?

If multiple users are requesting the same row at the same time, why not query the database only once?

This is exactly what Request Coalescing helps us achieve.


Here’s what happens under the hood:

- The first user that makes a request causes a worker task to spin up in the data service

- Subsequent requests for the same data will check for the existence of that task and subscribe to it

- Once the initial worker task queries the database and gets the result, it will return the row to all subscribers at the same time.


There are several pros to using Request Coalescing:

- Efficient utilization of database resources

- Ability to handle more concurrent requests without creating hot partitions

- Reduce latency


But there are some cons as well:

- Implementation can be complex with regards to getting a fair distributed reader-write lock. Basically, multiple readers need to access the data simultaneously while preventing conflicting writes

- Overall latency may go down, but certain requests will take more time


Of course, this technique is NOT needed normally. But at a certain scale, it can actually save your business.

Credits to Saurabh Dashora

Database Highload data architecture

"In all likelihood we’re not just seeing the death of the iPod Classic, but the death of the dedicated portable music player. Now it’s all phones and apps. Everything is a camera. The single-use device is gone—and with it, the very notion of cool that it once carried. The iPhone is about as subversive as a bag of potato chips, and music doesn’t define anyone anymore."
- On Death and iPods: A Requiem | WIRED (via thisistheverge)

(via theverge)

theverge wired devices music ipod ipod classic