/ukv

Replacing MongoDB, Neo4J, and Elastic with 1 transactional database. Features: zero-copy semantics, swappable backends, bindings for C, C++, Python, Java, GoLang

Primary LanguageC++Apache License 2.0Apache-2.0

Universal Keys & Values

Modular Transactional NoSQL Database
Bringing Zero-Copy Semantics into Storage


Youtube     Discord     LinkedIn     Twitter     Blog     GitHub

choose either: RocksDBLevelDB • UDisk • UMem
to store: Blobs • Documents • Graphs • Vectors • Texts
with drivers for: C • C++ • Python • Java • GoLang • Apache Arrow
available through: CMakePyPIDocker Hub

UKV is more than a database. It is a "build your database" toolkit and an open standard for NoSQL potentially-transactional databases, defining zero-copy binary interfaces for "Create, Read, Update, Delete" operations, or CRUD for short.

A few simple C99 headers can link almost any underlying storage engine to many high-level language bindings, extending their support for binary string values to graphs, flexible-schema documents, and other modalities, aiming to replace MongoDB, Neo4J, Pinecone, and ElasticSearch with a single ACID-transactional system.

UKV: Small Map

Redis, for example, provides RediSearch, RedisJSON, and RedisGraph with similar objectives. UKV does it better, allowing you to add your favorite Key-Value Stores (KVS), embedded, standalone, or sharded, such as FoundationDB, multiplying its functionality.


In the same way, you can add SDKs for other high-level languages or support for data types specific to your application that we haven't considered. This gives you the flexibility to iterate on different parts of this modular data lake without changing the business logic of your application, decoupling it from the underlying storage technology.

Documents Processing Performance Chart for UKV and MongoDB

Flexibility is essential, but so is performance. We prefer to avoid dynamic memory allocations across all modalities and choose libraries that share that mindset. For instance, the reference implementation of Document collections uses simdjson to read and yyjson to update docs, storing them in RocksDB and serving them through Apache Arrow Flight RPC. Even such a surprisingly obvious combination often outperforms commercial DBMS products. The UDisk-based version obliterates them.

Binary Processing Performance Chart for UKV and MongoDB

Modern persistent IO on high-end servers can exceed 120 GB/s per socket when built on user-space drivers like SPDK. This is close to the real-world throughput of eight-channel DDR4 memory. Making even a single copy of data on the hot path would slash that performance. Processing hundreds of terabytes per node, we couldn't have used LevelDB, RocksDB, or even their interfaces for our purposes to avoid dynamic polymorphism and any constraints on memory allocation strategies. That is how UKV began, but hopefully, it can grow further, advancing the storage ecosystem the same way the standardization of BLAS has pushed the frontiers of numerical compute and, later, AI.


Video intro on Youtube • Communications on Discord • Full documentation

         DOI         



Basic Use Cases

  1. Getting a Python, GoLang, or Java wrapper for vanilla RocksDB or LevelDB.
  2. Serving them via Apache Arrow Flight RPC to Spark, Kafka, or PyTorch.
  3. Embedded Document and Graph DB that will avoid networking overheads.
  4. Tiering DBMS between in-memory and persistent backends under one API.

Already excited? Give it a try. It is as easy as using dict in Python.

$ pip install ukv
$ python

>>> import ukv.umem as embedded
>>> db = embedded.DataBase()
>>> db.main[42] = 'Hi'
Same with persisted RocksDB
>>> import ukv.rocksdb as embedded
>>> db = embedded.DataBase('/tmp/ukv/rocksdb/')
Same with an arbitrary standalone UKV distribution
>>> import ukv.flight_client as remote
>>> db = remote.DataBase('grpc://0.0.0.0:38709')

Tabular, graph and other operations should also be familiar to anyone using Pandas or NetworkX. Function calls would look identical, but the underlying implementation may be addressing hundreds of terabytes of data placed somewhere in persistent memory on a remote machine.

>>> db = ukv.DataBase()
>>> net = db.main.graph
>>> net.add_edge(1, 2)
>>> assert net.has_edge(1, 2)
>>> assert net.has_node(1) and net.has_node(2)
>>> assert net.number_of_edges(1, 2) == 1

Features

A Key Value Store is generally an associative container with sub-linear search time. Every DBMS uses such abstractions for primary keys in each collection and indexes. But UKV has more to offer. Especially to Machine Learning practitioners.

  • ACID Transactions across collections
  • Persistent Snapshots 🔜 v0.5
  • Operation-level WATCH-es
  • BSON, JSON, MessagePack support
  • JSON Patches & Merge-Patches
  • JSON Pointers Addressing
  • Native Apache Arrow format support
  • Arrow Flight RPC server implementation
  • Bulk Scans, Random Sampling
  • Pandas Tabular interface
  • NetworkX Graph interface
  • PyTorch & TensorFlow Data-Loaders 🔜 v0.6

Available Backends

Any backend can be defined by three parameters. First, the Engine, being a Key-Value Store for the serialized representations. Second, implementations of Modalities, being various serialization and indexing approaches for structured data. Third, a Distribution form, such as the implementation of some web-protocol for communication with the outside world.

UKV: Backend

Engines

Following engines can be used almost interchangeably. Historically, LevelDB was the first one. RocksDB then improved on functionality and performance. Now it serves as the foundation for half of the DBMS startups.

LevelDB RocksDB UDisk UMem
Speed 1x 2x 10x 30x
Persistent
Transactional
Block Device Support
Encryption
Watches
Snapshots
Random Sampling
Bulk Enumeration
Named Collections
Open-Source
Compatibility Any Any Linux Any
Maintainer Google Facebook Unum Unum

UMem and UDisk are both designed and maintained by Unum. Both are feature-complete, but the most crucial feature our alternatives provide is performance. Being fast in memory is easy. The core logic of UMem can be found in the templated header-only ucset library.

Designing UDisk was a much more challenging 7-year long endeavour. It included inventing new tree-like structures, implementing partial kernel bypass with io_uring, complete bypass with SPDK, GPU acceleration, and even a custom internal filesystem. UDisk is the first engine to be designed from scratch with parallel architectures and kernel-bypass in mind.

Jump to Benchmarks.

Modalities

The same DBMS can contain multiple collections. Each collection can store BLOBs or any modality of structured data. Data of different modalities can't be stored in the same collection. ACID transactions across modalities are supported.

Documents Graphs Vectors
Values JSON-like Hierarchical Objects Labeled Directed Relations High-Dimensional Embeddings
Specialized Functionality JSON ⇔ BSON ⇔ MessagePack, Sub-Document Operations Gather Neighbors, Count Vertex Degrees Quantization, K-Approximate Nearest-Neighbors Search
Examples MongoDB, Postgres, MySQL Neo4J, TigerGraph Elastic Search, Pinecone

One of our core objectives was to select the minimal core set of functions for each modality. In that case, implementing them can be easy for any passionate developer. If the low-level interfaces are flexible, making the high-level interfaces rich is easy.

Available Frontends

UKV for Python and for C++ look very different. Our Python SDK mimics other Python libraries - Pandas and NetworkX. Similarly, C++ library provides the interface C++ developers expect.

UKV: Frontends

As we know, people use different languages for different purposes. Some C-level functionality isn't implemented for some languages. Either because there was no demand for it, or as we haven't gotten to it yet.

Name Transact Collections Batches Docs Graphs Copies
C Standard 0
C++ SDK 0
Python SDK 0-1
GoLang SDK 1
Java SDK 1
Arrow Flight API 0-2

Some frontends here have entire ecosystems around them! Apache Arrow Flight API, for instance, has its own bindings for C, C++, C#, Go, Java, JavaScript, Julia, MATLAB, Python, R, Ruby and Rust.

UKV: Frontends

Documentation

For guidance on installation, development, deployment, and administration, see our documentation.

Installation

The entire DBMS fits into a sub 100 MB Docker image. Run the following script to pull and run the container, exposing Apache Arrow Flight server on the port 38709. Client SDKs will also communicate through that same port, by default.

docker run -d --rm --name ukv-test -p 38709:38709 unum/ukv

For C/C++ clients and for the embedded distribution of UKV, CMake is the default form of installation. It may require installing Arrow separately, if you want client-server communication.

FetchContent_Declare(
    ukv
    GIT_REPOSITORY https://github.com/unum-cloud/ukv.git
    GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(ukv)
include_directories(${ukv_SOURCE_DIR}/include)

After that, you only need to choose linking target, such as ukv_embedded_rocksdb, ukv_embedded_umem, ukv_flight_client, or something else.

For Python users, it is the classical:

pip install ukv

Which will bring all the libraries packed into a single wheel: ukv.umem, ukv.rocksdb, ukv.leveldb, ukv.flight_client.

Read full installation guide in our docs here.

Getting Started

Testing

We split tests into 4 categories:

  1. Compilation: Validate meta-programming.
  2. API: Prevent passing incompatible function arguments.
  3. Unit: Short and cover most of the functionality.
  4. Stress: Very long and multithreaded.

All unit tests are packed into a single executable to simplify running it during development. Every backend produces one such executable. The in-memory embedded variant is generally used for debugging any non-engine level logic.

The stress tests, on the other hand, can run for days and simulate millions of concurrent transactions, ensuring the data remains intact. Any additions, especially to the stress tests, will be highly welcomed!

Read full testing guide in our docs here.

Benchmarks

It is always best to implement an application-specific benchmark, as every use case is different. Still, for the binary layer logic, we have built a dedicated project to evaluate persistent data structures - UCSB. It doesn't depend on UKV and uses native interfaces of all the engines to put everyone in the same shoes.

All engines were benchmarked for weeks using UCSB. We have already published the results for BLOB-layer abstractions for 10 TB, and, previously, 1 TB collections.

For more advanced modality-specific workloads, we have the following benchmarks provided in this repo:

  • Twitter. It takes the .ndjson dump of their GET statuses/sample API and imports it into the Documents collection. We then measure random-gathers' speed at document-level, field-level, and multi-field tabular exports. We also construct a graph from the same data in a separate collection. And evaluate Graph construction time and traversals from random starting points.
  • Tabular. Similar to the previous benchmark, but generalizes it to arbitrary datasets with some additional context. It supports Parquet and CSV input files. 🔜
  • Vector. Given a memory-mapped file with a big matrix, builds an Approximate Nearest Neighbors Search index from the rows of that matrix. Evaluates both construction and query time. 🔜

We are working hard to prepare a comprehensive overview of different parts of UKV compared to industry-standard tools. On both our hardware and most common instances across public clouds.

Read full benchmarking guide in our docs here.

Tooling

Tools are built on top of the UKV interface and aren't familiar with the underlying backend implementation. They are meant to simplify DevOps and DBMS management. Following tools are currently in the works.

  • Bulk dataset imports and exports for industry-standard Parquet, NDJSON and CSV files. 🔜
  • Rolling backups and replication. 🔜
  • Visualization tools and dashboards. 🔜

Read full tooling guide in our docs here.

Roadmap

Our development roadmap is public and is hosted within the GitHub repository. Upcoming tasks include:

  • Builds for Arm, MacOS, Windows.
  • Richer bindings for GoLang, Java, JavaScript.
  • Improved Vector Search.
  • Collection-level configuration.
  • Owning and non-owning C++ wrappers.
  • Document-schema validation.
  • Persistent Snapshots.
  • Continuous Replication.
  • Horizontal Scaling.

Read full roadmap in our docs here.

Contributing

UKV is an umbrella project for many FOSS libraries. So any work on libraries like simdjson, yyjson, RocksDB, or Apache Arrow, indirectly benefits UKV. To participate in the UKV directly, please check out the guide and implementation details. Thank you!

Read full development and contribution guide in our docs here.

Frequently Asked Questions

  • Keys are 64-bit integers, by default. Why?
  • Values are binary strings under 4 GB long. Why?
  • Transactions are ACI(D) by-default. What does it mean?
  • Why not use LevelDB or RocksDB interface? Answered
  • Why not use SQL, MQL or Cypher? Answered
  • Does UKV support Time-To-Live? Answered
  • Does UKV support compression? Answered
  • Does UKV support queues? Answered
  • How can I add Bindings for language X? Answered
  • How can I add database X as an Engine? Answered