Distributed, high-performance blob storage on SQLite

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Distributed, high-performance blob storage on SQLite

Distributed, high-performance blob storage on SQLite 19 Nov 2026 Sarat Chandra Software Engineer

基于 SQLite 的分布式高性能 Blob 存储 2026 年 11 月 19 日 Sarat Chandra 软件工程师

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.

简而言之:我们构建了 Blobasaur,这是一个基于 SQLite 的分片式、分布式、轻量级 Blob 存储服务器,旨在解决我们高吞吐量 Blob 读写的使用场景。现在,在普通硬件上,大小从几 KB 到几 MB 不等的 JSON Blob 每秒可被读写数千次,同时保持个位数的毫秒级延迟。

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 customizing 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.

在我们的交易平台 Kite 上,约有 2000 万客户可以深度定制他们的投资和交易界面。他们会保存多图表布局、金融指标模板、矢量绘图以及各种任意的 UI 偏好设置。此外,我们还提供了一种终端模式,允许用户通过拖放和自定义小部件来设计自己的工作区。在底层,我们的后端服务将这些用户偏好和元数据存储为不透明的 Blob(主要是 JSON),大小从几 KB 到几 MB 不等。

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 it very easy to integrate as well. SSDB solved our immediate performance problems and ran reliably in production for several years.

多年前,我们将这些 Blob 存储在 CouchDB 中,但事实证明它并不适合我们当时开始面临的那种吞吐量。随后,我们转向了 SSDB,这是一个支持 Redis 协议的 C++ 磁盘存储系统。这使得集成变得非常容易。SSDB 解决了我们当时的性能问题,并在生产环境中稳定运行了几年。

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.

随着时间的推移,两个问题迫使我们寻找替代方案: SSDB 停止了维护,这构成了明显的运营风险。它由 C++ 编写,而这并非我们的技术栈或专长,因此对其进行分支和维护也是不可行的。 扩展性和大小限制。SSDB 不是分布式系统,只能在单节点上运行。这给未来的扩展带来了巨大的挑战,甚至曾一度迫使我们将 Blob 大小限制在 1 MB 以内,因为在处理更大的负载时延迟会显著增加。

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 maintainable and highly economical.

随着我们增加了终端模式等功能并接入了更多内部服务,我们需要一个稳健的解决方案。我们的标准如下: 一个具有简单 API 的键值 Blob 存储。 专为多 MB 的 Blob 读写操作和高吞吐量而设计。我们需要承受每秒数千到数万次读写任意 Blob 的负载。由于股市的波动,这些负载具有不可预测性和突发性。 可水平扩展、分布式。 磁盘空间效率/压缩。 易于维护且非常经济。

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.

因此,我们研究了针对高吞吐量 Blob 存储优化的 FOSS 数据库,并考察了以下方案: ScyllaDB:我们已经在高吞吐量工作负载中使用 ScyllaDB,但在测试中,它在大 Blob 存储方面表现不佳。吞吐量显著降低,资源占用更高。我们特别需要多 MB 的 Blob。频繁覆盖和 TTL 过期产生的墓碑记录(Tombstones)在 ScyllaDB 中需要仔细调优。 PostgreSQL:我们在技术栈中已有丰富的 Postgres 使用经验,并尝试过将 Blob 存储为 BYTEA 列,但事实证明,在性能和磁盘空间效率方面,它对于该用例来说表现极差。 YugabyteDB:虽然提供 Blob 存储选项,但并非主要为此设计或优化。此外,它是一个功能过多的庞大系统。 RocksDB:具备合适的原语,但同样不是为高吞吐量、多 MB 的 Blob 写入而架构的。 Ceph:运营复杂度和资源需求过高。我们甚至没有尝试。 SeaweedFS:这是最接近的候选者。然而,存在一些阻碍。我们的用例是针对同一键的频繁覆盖(用户更改工作区),而 SeaweedFS 在压缩前会不断追加,这可能导致磁盘使用量失控。Blob 有自己的 ID,必须在单独的数据库中映射到用户键,这增加了一层复杂性。它不支持每个 Blob 的 TTL。此外,其设置相当复杂,涉及多个组件。 S3 和 MinIO:对象存储在处理小 Blob 时单次请求延迟较高,在写入密集型工作负载(写入占我们流量的 50%)下请求成本高昂,且生命周期 TTL 较粗糙,而非精确的键过期。更不用说,考虑到每秒数千次操作和每天数千万次操作,S3 将产生巨大的成本。 原始文件系统(每个 Blob 一个文件):直接将 Blob 放在磁盘上意味着需要实现原子写入和写入批处理,管理大量文件和目录,处理传统的原子读写磁盘性能和 inode 问题,并维护一个单独的 TTL 元数据索引。更不用说还要在 AWS 存储卷上进行编排。

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?

大约在这个时候,我们在另一个项目中尝试使用 SQLite,并对其“比文件系统快 35%”的声明感到惊叹。我们恰好还有一个查询缓存系统,每天在 Postgres 实例中创建数百万个表,这非常成功地将数据库推向了极限。综合考虑,我们想,为什么不基于 SQLite 构建一个系统来存储数百万个 Blob,看看会发生什么呢?

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.

最终,我们构建了 Blobasaur,这是一个用 Rust 编写的开源分片 Blob 服务器,它支持 Redis 协议并使用 SQLite 作为存储引擎。它是一个高性能的单一二进制应用程序,部署和维护非常简单。它目前在 Zerodha 的生产环境中使用,并已成功取代了 SSDB。

What we needed We had several Go and Python services already talking to SSDB via the Redis protocol, with more waiting to onboard. 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). 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 TTL

我们的需求 我们已经有几个 Go 和 Python 服务通过 Redis 协议与 SSDB 通信,还有更多服务等待接入。我们希望新方案满足以下要求: Redis 协议兼容性(如果可能的话):每个现有客户端都已经使用了标准的 Redis 库(GET、SET、HGET、HSET、DEL、EXPIRE)。如果我们能获得一个可以直接替换的系统,这将使我们无需改动现有服务,并显著降低风险。 跨负载大小的低延迟:它需要同时为 2 KB 的设置 Blob 和 5 MB 的图表布局提供服务,并保持个位数的毫秒级延迟。 内置压缩:我们几乎所有的负载都是重复的 JSON,压缩效果很好。 带有 TTL 的简单 CRUD。