文章摘要
Perplexity为解决亚马逊DynamoDB在超20万QPS高负载下成本不可持续、内部不透明、读写资源冲突等问题,将核心搜索服务层存储迁移至自研、用Rust编写的分布式键值存储CobbleDB,重构了存储架构。迁移后性能大幅提升,实现降本提效;该系统约4万行代码,由两名工程师搭配AI编码工具两个月开发完成,后续计划开源,同时存在需自主运维等取舍。

Perplexity has completed a key migration of its core search service layer from Amazon DynamoDB to CobbleDB, an internally developed distributed key-value storage system written in Rust. This move was driven by pressing challenges encountered under high query loads, and it has already delivered significant improvements in performance and cost efficiency.

The migration addressed two primary pain points. First, at production scales exceeding 200,000 requests per second, DynamoDB’s pay-per-byte billing model became economically unsustainable. Second, as a black-box service, DynamoDB offered no visibility into internal details like partition placement, memory caching strategies, or replica routing—making it impossible to avoid tail latency spikes caused by un-cached reads, cross-availability zone network hops, or replica delays. Additionally, reprocessing jobs triggered by updates to chunking algorithms or new embedding models would flood DynamoDB with large write volumes, leading to resource contention with real-time user queries.

To resolve these issues, Perplexity restructured its storage architecture into three specialized components. The first is Pillar, which uses high-capacity mechanical hard drives running YTsaurus to maintain versioned tables for web metadata, paragraphs, and vector representations, with YTsaurus atomic transactions ensuring coordinated submission of crawl updates, state changes, and export queues. The second component is Lorry, a stateless queue consumer that aggregates content from Pillar into partition-aligned batch files, stores the payloads in S3, and sends metadata notifications to CobbleDB. The third component is CobbleDB itself, which operates independently by pulling and ingesting these S3 batches, isolating hot data service nodes from write-intensive crawl pipelines.

CobbleDB is purpose-built for optimized batch lookups. Each partition maintains three replicas across separate compute nodes, with its core daemon using RocksDB as an embedded storage engine, supplemented by memory-mapped caching and local NVMe solid-state drives. A stateless query router maps hashed page identifiers to partitions and coordinates read operations, minimizing network overhead by directing requests to replicas in the same availability zone. If a target replica’s response time rises, the router employs speculative hedging—sending a read request to a spare replica in another node simultaneously. Internally, CobbleDB leverages RocksDB’s batched MultiGet interface to retrieve multiple keys at once, eliminating round-trip latency.

pub struct BatchedPageRequest {
    pub keys: Vec<PageKey>,
    pub zone_affinity: AvailabilityZone,
}

impl StorageEngine {
    pub fn multi_get_pages(&self, keys: &[PageKey]) -> Result<Vec<Option<PageRecord>>, Error> {
        let rocksdb_keys: Vec<&[u8]> = keys.iter().map(|k| k.as_bytes()).collect();
        self.rocksdb.batched_multi_get(&rocksdb_keys)
    }
}

Unlike standard distributed databases, CobbleDB omits traditional distributed transaction protocols and synchronous consensus algorithms. Since search services can tolerate minor replication delays, each replica applies updates asynchronously at its own pace, drastically reducing operational overhead.

Production measurements confirm the migration’s success: CobbleDB cut median batch read latency from 31.4 milliseconds to 5.6 milliseconds, p90 latency from 56.7 milliseconds to 9.77 milliseconds, and p99 tail latency from 123 milliseconds to 24.2 milliseconds. Synthetic benchmark tests handling payloads up to 100 KB show that CobbleDB maintains stable throughput even at rates up to 500,000 requests per second.

This architecture does come with tradeoffs. Replacing a fully managed cloud database with a custom-built system means internal site reliability engineers must handle all node lifecycle management, backup validation, and partition rebalancing. Additionally, since replicas ingest batch files at different intervals, applications need to support eventual consistency.

Perplexity’s CEO Aravind Srinivas noted that CobbleDB consists of approximately 40,000 lines of Rust code, developed over two months by two system engineers working alongside a cluster of autonomous AI coding agents. These AI agents handled tasks like integration testing, build monitoring, and maintenance manual creation. The company plans to release the CobbleDB codebase as open source in an upcoming version.

以上内容不代表本平台立场,仅供读者参考