mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[GH-ISSUE #2993] [RFC]: Distributed KV Storage Backend for Mooncake Store #773
Labels
No labels
ascend
auto-closed
bug
bug
CI/Build
Common
documentation
enhancement
feature request
good first issue
help wanted
high priority
MetaX
nightly-failure
pull-request
PyTorch Backend
question
RFC
Roadmap
stale
Store
Tests
Transfer Engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/Mooncake#773
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @henian-Ni on GitHub (Jul 20, 2026).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/2993
[RFC]: Distributed KV Storage Backend for Mooncake Store
1. Introduction
This proposal introduces a Distributed KV Storage Backend for Mooncake Store as the fourth storage-backend implementation (alongside
FilePerKey,Bucket, andOffsetAllocator). Through theIDistributedKVClientabstraction, it interfaces with external distributed KV stores, extending Mooncake's offload storage from the local filesystem to distributed KV storage devices.The only implementation today is
UbsKVClient, which provides NVMe KV SSD access by dynamically loading the UBSIO KV Cache library (libubsio_kvc.so).DistributedKVStorageBackendimplementsStorageBackendInterfaceand plugs into the existingFileStoragepipeline, requiring no changes to upper-layer application code.Goal: give Mooncake Store a low-cost, large-capacity distributed KV storage tier that bypasses filesystem overhead and talks to the underlying storage devices directly through a KV interface, suitable for large-scale KV Cache offload scenarios.
2. Background and Motivation
As long-context scenarios proliferate (multi-turn conversation, coding assistants, document understanding), KV Cache sizes keep growing. DRAM is expensive and capacity-constrained, making it insufficient for large-scale KV Cache storage.
Mooncake's existing storage backends (
FilePerKeyBackend,BucketBackend,OffsetAllocatorBackend) all operate through the filesystem layer — each offload/load maps to file create / open / write-or-read / close syscalls. This per-file overhead becomes a bottleneck under high-frequency, fine-grained I/O workloads.Advantages of a distributed KV storage backend:
Put/Get/Delbatch APIs, bypassing the filesystem and eliminating per-file syscall overhead.IDistributedKVClientinterface allows different KV storage implementations to be wired in; the UBSIO implementation is provided today, and others can be added in the future.libubsio_kvc.sois loaded at runtime viadlopen/dlsym, with no compile-time linking, keeping deployment flexible.UbsKVClient::BatchGetleverages UBSIO's zero-copy interface (UbsioBatchGetreturns a device-side pointer), reducing data-movement overhead.3. Technical Design
3.1 Architecture Overview
The integration follows Mooncake's existing storage-backend abstraction.
DistributedKVStorageBackendimplementsStorageBackendInterfaceand talks to the underlying KV storage engine through theIDistributedKVClientabstraction layer.3.2 IDistributedKVClient Interface
IDistributedKVClientis a user-facing abstract interface that allows custom KV storage implementations:Init()virtual ErrorCode Init() = 0BatchPut()virtual tl::expected<vector<int>, ErrorCode> BatchPut(keys, values) = 0BatchGet()virtual ErrorCode BatchGet(keys, dest_slices) = 0Exists()virtual tl::expected<bool, ErrorCode> Exists(key) = 0ScanKeys()virtual ErrorCode ScanKeys(handler) = 03.3 UbsKVClient Implementation
UbsKVClientis the UBSIO implementation ofIDistributedKVClient:libubsio_kvc.soviaDlUbsioApi::LoadLibrary(), then callsUbsioClientInit()to initialize the client.vector<string>into a C-style pointer array and callsUbsioBatchPut()for the batch write.UbsioBatchGet()to obtain a device-side zero-copy pointer,memcpys into the target Slice, and then asynchronously callsUbsioBatchFreeAddress()(via a thread pool) to release the device-side memory.UbsioExist()to check key existence.3.4 DlUbsioApi — Dynamic Library Loading
DlUbsioApiwraps the loading and invocation of the UBSIO dynamic library:dlopen/dlsymto loadlibubsio_kvc.soat runtime.UbsioClientInit/Put/Get/Exist/Delete/GetLength/BatchPut/BatchGet/BatchGetDirect/BatchExist/BatchDelete/BatchGetLength/BatchFree.std::mutex).3.5 StorageBackendInterface Integration
DistributedKVStorageBackendimplementsStorageBackendInterface:Init(): creates and initializes anUbsKVClient.BatchOffload(): concatenates multiple Slices into a contiguous byte string, callsBatchPutto write to the KV backend, and on success notifies the master viacomplete_handlerto add aLOCAL_DISKreplica.BatchLoad(): reads data from the KV backend into an RDMA-registered CPU ClientBuffer.IsExist(): delegates tokv_client_->Exists().IsEnableOffloading(): checkstotal_size_ < total_size_limit && total_keys_ < total_keys_limit.ScanMeta(): scans existing data, invoking the handler in batches to restore master metadata.Backend registration:
StorageBackendType::kDistributedKV.CreateStorageBackend()factory instantiatesDistributedKVStorageBackendon a type match.MOONCAKE_OFFLOAD_STORAGE_BACKEND_DESCRIPTOR=distributed_kv_storage_backend.3.6 Data Flow
3.7 Configuration
Activated via an environment variable:
FileStorageConfig::Validate()skips thestorage_filepathpath validation for thekDistributedKVtype (the KV backend needs no local file path).4. Key Source Files
mooncake-store/include/storage_backend.hIDistributedKVClient,UbsKVClient,DistributedKVStorageBackend,StorageBackendType::kDistributedKVmooncake-store/include/dl_ubsio_api.hDlUbsioApi; declares all ubsio C function-pointer typesmooncake-store/src/storage_backend.cppUbsKVClientandDistributedKVStorageBackendmooncake-store/src/dl_ubsio_api.cppDlUbsioApi::LoadLibrary()/CleanupLibrary()implementationmooncake-store/src/file_storage.cppValidate()path-skip,Heartbeat()empty-list optimizationmooncake-store/src/CMakeLists.txtdl_ubsio_api.cppto the build listmooncake-store/tests/storage_backend_test.cppMockDistributedKVClient+ 18DistributedKVStorageBackendunit tests5. Test Coverage
storage_backend_test.cppcontains 18DistributedKVStorageBackendtest cases:Tests use
MockDistributedKVClient(an in-memory map simulating the KV store) and injectkv_client_directly viafriend class StorageBackendTest.6. Current Limitations & Future Work
UbsKVClient::ScanKeys()only logs an error and returnsOKScanMeta— a critical missing capabilityeviction_handleris ignored; data in the KV backend only growsInit()directly doesmake_unique<UbsKVClient>(); no config injection of otherIDistributedKVClientimplementationsmemcpyinto the target Slice is still neededDlUbsioApiwrapsUbsioBatchGetWithHBM, butUbsKVClient::BatchGetdoes not use itDlUbsioApiwrapsUbsioDelete/UbsioBatchDelete, but the backend never calls themValidate()only skips path validation; no KV-backend-specific config validationatomic<bool>double-check, but two threads may still create anUbsKVClientconcurrently7. Compatibility
DistributedKVStorageBackendfully implementsStorageBackendInterface; all callers usingFileStorageneed no changes.BucketBackend,FilePerKeyBackend,OffsetAllocatorBackend) are entirely unaffected.libubsio_kvc.sois loaded at runtime viadlopen, with no compile-time linking; its absence does not affect other backends.8. Alternatives Considered
SSD KV Engine (#1990): that proposal compiles SSD KV Engine as a static library integrated into Mooncake Store, providing self-contained single-node SSD offload. By contrast, this proposal's
DistributedKVStorageBackendsupports distributed KV storage through theIDistributedKVClientabstraction layer, focusing more on storage expansion in multi-node scenarios. The two can coexist, covering single-node and distributed cases respectively.NVMe KV Backend (#1957): that proposal introduces a four-layer Backend → Connector → Executor separation — more complete in architecture but also more complex. The current implementation can be viewed as a simplified version of that architecture (
DistributedKVStorageBackend≈ Backend,UbsKVClient≈ Connector,DlUbsioApi≈ Executor), and can gradually evolve toward the full architecture later.@github-actions[bot] commented on GitHub (Jul 20, 2026):
Thanks for opening this issue, @henian-Ni!
66468415A maintainer will triage this when possible. To help us respond faster, please include:
Useful links: Documentation · Contributing guide
@github-actions[bot] commented on GitHub (Oct 19, 2026):
This issue has had no activity for 90 days and will be closed in 7 days if there is no further activity. Please comment or react if it should stay open.
@github-actions[bot] commented on GitHub (Oct 26, 2026):
Closing due to 3 months of inactivity. If this is still relevant, please comment and we can reopen.