Skip to content
HN On Hacker News ↗

Distributed, high-performance blob storage on SQLite - Zerodha Tech Blog

▲ 286 points • 72 comments • by ghostfoxgod • 4d ago • HN discussion ↗

Pangram verdict · v3.3

We believe that this text is a mix of AI and human-written content.

28 %

AI likelihood · overall

Mixed
72% human-written 28% AI-generated
SEGMENTS · HUMAN 6 of 13
SEGMENTS · AI 7 of 13
WORD COUNT 1,520
PEAK AI % 100% · §3
Analyzed
Nov 19
backend: pangram/v3.3
Segments scanned
13 windows
avg 117 words each
Distribution
72 / 28%
human / AI fraction
Verdict
Mixed
Pangram v3.3

Article text · 1,520 words · 13 segments analyzed

Human AI-generated
§1 Human · 0%

TLDR; We built Blobasaur, a sharded, distributed, lightweight blob storage server on top of SQLite to solve our high-throughput blob read/write usecase. JSON blobs varying from a few KBs to MBs are now written and read thousands of times per second on commodity hardware while maintaining single-digit millisecond latency.On Kite, our trading platform with ~20 million customers, users are able to customize their investment and trading screens heavily. They save multi-chart layouts, financial indicator templates, vector drawings, and various kinds of arbitrary UI preferences. In addition, we offer a Terminal mode that allows users to design their own workspaces by dragging, dropping, and customing widgets. Under the hood, our backend services store these user preferences and metadata as opaque blobs (mostly JSON) ranging from a few kilobytes to several megabytes.Many years ago, we stored such blobs in CouchDB, which turned out to be ill-suited for the kind of throughput we were starting to see. We then moved to SSDB (ssdb), a C++ disk-backed store that speaks the Redis protocol. This made is very easy to integrate as well. SSDB solved our immediate performance problems and ran reliably in production for several years.Over time, two problems forced us to look for a replacement:SSDB became unmaintained, which was an obvious operational risk. It is written in C++, which is not a part of our stack or expertise, so forking and maintaining was also not viable.Scaling and size limits. SSDB is not a distributed system and can only run on a single node. This imposes significant future scaling challenges, including at one point forcing us to cap blob sizes at 1 MB because latency degrades on larger payloads. As we added features like the Terminal mode and onboarded more internal services, we needed a robust solution. Our criteria were:A key-value blob store with a simple API.Designed for multi-megabyte blob read/write ops and high throughput. We sustain loads of thousands to tens of thousands of requests per second reading and writing arbitrary blobs. These are unpredictable and bursty thanks to the volatility in stock markets.Horizontally scalable, distributed.Disk-space efficiency / compression.Easily maintenanble and highly economical.So we investigated FOSS databases optimized for high-throughput blob storage and looked at the following:ScyllaDB: We already run ScyllaDB for high-throughput workloads, but in our tests, it turned out to be suboptimal for large blobs. Significantly lower throughput and higher resource usage. We specifically want multi-megabyte blobs. Tombstones from frequent overwrites and TTL expiries require careful tuning in ScyllaDB.PostgreSQL: We already have considerable experience with Postgres in our stack and experimented with storing blobs as BYTEA columns, but it turned out to be severely suboptimal again for the use case in terms of performance and disk-space efficiency.YugabyteDB: Has blob storage as one of the options, but is not primarily designed or optimized for it. Also, a large system with too many features.RocksDB: Had the right primitives, but again, not architected for high throughput multi-MB blob writes.Ceph: Severe operational complexity and resource requirements. We didn’t even get to trying it out.SeaweedFS: This was the closest candidate. However, there were a few blockers. Our use case is overwrite-heavy (a user changing their workspace) over the same key, and SeaweedFS keeps appending before compaction, which can cause disk usage to grow uncontrollably. Blobs have their own IDs, which then have to be mapped against user keys in a separate DB, adding another layer. It doesn’t support TTL per blob. Also, reasonably complex setup with many parts.S3 and MinIO: Object storage has high per-request latency for small blobs, high request costs under write-heavy workloads (writes are 50% of our traffic), and coarse lifecycle TTLs instead of exact key expiry. Not to mention, S3 would incur significant costs given thousands of ops per second and tens of millions of ops per day.Raw filesystem (one file per blob): Putting blobs directly on disk meant implementing atomic writes and write batching, managing large numbers of files and directories, good old atomic read/write disk performance and inode headaches, and maintaining a separate metadata index for TTLs. Not to mention, orchestrating this over AWS storage volumes.Around this time, we were toying with SQLite for another project and were marveling at its 35% Faster Than The Filesystem claim. We also happen to have a query cache system that creates millions of tables every day in a Postgres instance, which pushes the database to its limits quite successfully. Putting two and two together, we thought, why not build a system on top of SQLite to store millions of blobs and see what happens?So we ended up building Blobasaur, an open source sharded blob server written in Rust that speaks the Redis protocol and uses SQLite as its storage engine. It is a single binary application that is high performance, and super simple to deploy and maintain. It is in production at Zerodha and it has successfully replaced SSDB.What we neededWe had several Go and Python services already talking to SSDB via the Redis protocol, with more waiting to onboard.

§2 AI · 100%

We wanted the new solution to meet these requirements:Redis protocol compatibility (if possible at all): Every existing client already used standard Redis libraries (GET, SET, HGET, HSET, DEL, EXPIRE).

§3 AI · 100%

If we could get a system that could be a drop-in replacement, that would allow us to leave existing services untouched and reduce risk significantly.Low latency across payload sizes: It needed to serve both 2 KB settings blobs and 5 MB chart layouts with single-digit millisecond latency.Built-in compression: Almost all our payloads are repetitive JSON, which compresses well.Simple CRUD with TTLs: We didn’t need complex data structures, server-side scripting, or secondary queries.

§4 Human · 3%

We just needed key-value and hash CRUD with key expiry.Multi-node partitioning: We needed to split data across multiple machines so a single node wasn’t a bottleneck.Relaxed durability is acceptable: This store holds non-critical UI and workspace preferences, and not critical financial data. If a sudden power loss drops recent writes, a user might lose a recent chart layout tweak, which is annoying, but it never affects trading.

§5 Human · 0%

This was a good performance trade-off for our use case.Why SQLite (and Rust)We had a few options for the storage. The obvious one is the raw filesystem, with one file per blob. But with that, we’d need to invent everything ourselves:Atomic writes and batching.TTL cleanup, which needs secondary indexes or walking the directories.Dealing with fd limits.Managing metadata separately from the raw data.SQLite pretty much gave us everything that the raw filesystem lacked. For small blobs, SQLite is up to 35% faster than raw filesystem I/O. While raw files start to beat SQLite above ~100 KiB, we compress blobs before writing them. And thankfully, 99% of our compressed values sit well below 100 KiB.Using SQLite also meant inheriting a battle-tested storage engine with ACID transactions, crash recovery, and standard tooling. Any shard on disk can be inspected with the standard sqlite3 CLI or queried with plain SQL for analytics, etc.While most of our backend stack is written in Go, we wrote Blobasaur in Rust.

§6 AI · 100%

Go’s standard SQLite driver requires CGo, which complicates static builds, pins OS threads during C calls under high concurrency, and adds garbage-collection pressure when allocating and compressing multi-megabyte buffers.

§7 Human · 0%

With Rust (sqlx, rusqlite, and tokio), we call SQLite’s C API directly with predictable memory usage and ship a single static binary.ArchitectureSplitting data into shardsIn WAL (Write-Ahead Logging) mode, a single SQLite database allows concurrent readers, but still permits only one writer at a time.

§8 Human · 0%

Since writes make up roughly 50% of our production traffic, a single SQLite file per node would bottleneck quickly.To get write concurrency on a single machine, Blobasaur splits data across multiple SQLite database files on disk, called shards:Consistent hashing: Each key maps to one shard via multi-probe consistent hashing.Per-shard writer with group commit: Each shard has a dedicated writer task fed by a bounded queue.

§9 AI · 100%

Instead of committing one key at a time, the writer drains a batch of pending writes from the queue and executes them inside a single BEGIN IMMEDIATE ...

§10 AI · 100%

COMMIT transaction.

§11 AI · 100%

This amortizes transaction and WAL overhead across concurrent clients.Concurrent readers: Reads go directly to a per-shard pool of read-only SQLite connections and can run concurrently with the writer.How much does sharding help?We benchmarked 1 shard against 16 shards using a load generator opening 64 concurrent connections. Each request used a 64 KiB JSON blob payload (close to our production average), which zstd compresses roughly 9x.All runs used 100,000 keys, synchronous writes, and batch_size = 50, with the data directory on tmpfs to isolate SQLite locking and CPU overhead from disk variance.

§12 Human · 0%

Both setups received the same total resources: 1,600 MB of SQLite page cache and 64 total read connections.Workload1 shard16 shardsHSET only7,740 ops/s, p99 10.7 ms25,324 ops/s, p99 8.3 ms50% HSET, 50% HGET14,227 ops/s, p99 10.5 ms29,538 ops/s, p99 8.5 msHGET only67,128 ops/s, p99 2.1 ms70,884 ops/s, p99 2.3 msWith 16 shards, write throughput increases 3.3x and median write latency drops from 8.2 ms to 2.1 ms.

§13 AI · 100%

Read throughput stays nearly identical because SQLite WAL mode already serves concurrent readers without contention.At 25,324 HSET operations per second, each carrying a 64 KiB payload, Blobasaur processes roughly 1.66 GB/s of uncompressed JSON through zstd.