Introducing BARCH
May 11, 2026 ยท View on GitHub
BARCH is a low-memory, dynamically configurable, constant access time ordered cache similar to valkey and redis
Additionally, it has an embedded server+client for python which can reduce read latency to micro-seconds. It implements the Z* (OrderedSet), H* (HashSet) and key value API's available in redis. A demo ubuntu 22.04 docker image is available at teejip/barch:v0.4.2.6b
Advantages of the embedded L1 server
- far lower read latency (sub micro-second instead of milli-seconds)
- automatic scaling (to a point)
- concurrency through sharding
- optionally serverless (L1 only or L1 + L2)
- future work may add object stores such as S3 or dynamo as L2 or even L3 layers
The embedded server can also run in a multi-writer replication configuration in conjunction with a standalone server. An embedded server can also be quickly synchronized with a standalone server using the block load api.
- See python example
Some Benchmarks
Features
- Ordered: minimum, lower-bound and maximum operations are constant time
- Low memory footprint: Half that of standard hash map while providing similar single threaded latency
- Also see Compression
- Dynamic config: All options can be configured at runtime without restarts or reload
- Scalability: All reads are concurrent and scales linearly with core count
Use Cases
- Fast Ranged Queries, Prefix Queries and Aggregates
- Prefix-cache for fast loading of hints
- Z-Order/Morton code range queries for quick spatial bounds checking
- Fast and accurate counting of small ranges (age, population etc) See ZfastRank
- Many small key value pairs in small footprint with minimal overhead
- Constant time access priority queue
Installation and Running
Note: BARCH builds to multiple shared libraries for different environments.
Checkout and build on (currently linux only) with gcc 10 or above...
-
Install python development tools
sudo apt update && sudo apt upgrade -y sudo apt install -y build-essential make curl ca-certificates libssl-dev libffi-dev sudo apt install -y python3-pip python3-venv python3-full sudo apt install cmake -
REQUIRED: install swig (to generate luajit, python and java bindings)
sudo apt install swig -
OPTIONAL: install jdk and maven - for barchjni, barchj and running java examples. Examples for java are located in examples/java/barchj.
sudo apt install default-jdk sudo apt install maven -
OPTIONAL: install openresty for barchlua (luajit) -
- Follow instructions for openresty at https://openresty.org/en/linux-packages.html#ubuntu
- after building barch for lua should be located in the /var/lib/lua/5.1/barch.so
- To install:
sudo cmake --install . --component barchlua
-
NOTES:
- The build will download valkey sources and build lbarch which is the barch valkey runtime for the
B.*api's. - Barch can run without valkey as a python library in which case you can connect to the barch resp port of your choice using redis-cli or valkey-cli. See the examples/flask/server.py for more information on how to do this.
- The build will download valkey sources and build lbarch which is the barch valkey runtime for the
-
FINALLY:
-
Build with cmake (barchj and lbarch will be built if the environments from above is detected)
cmake -B build -DTEST_OD=ON cmake --build build --target barch --parallel cmake --build build --target lbarch --parallel -
Test:
ctest -
start
valkey-server valkey.conf --loadmodule {src code location}/build/_barch.so -
install barch for lua (In build directory)
sudo cmake --install . --component barchlua
-
Or alternatively Via Docker image
Docs
Configuration
See Configuration docs
Hardware Compatibility
- amd64+sse
- arm+neon
Toolchain Compatibility
- Debian + gcc 11+
- any compiler that supports C++ 20
Server Environment
- Valkey v. 8.0+
- any python 3.10 program
BARCH specific API's implemented
MIN MAX
SIZE SAVE
PUBLISH LB, FIRST
START STOP
RETRIEVE LOAD
ADDROUTE ROUTE
REMROUTE OPS
STATS UB, NEXT
COUNT SPACE
USE VALUES
Other VALKEY API's implemented (Mostly Key Value + TTL)
AUTH ACL
SET KEYS
INCR INCRBY
UINCRBY UDECRBY
DECR DECRBY
MSET DEL
GET MGET
REM FLUSHDB/FLUSHALL
PING TTL
EXPIRE EXISTS
DBSIZE MULTI
EXEC CLIENT INFO
INFO APPEND
KEYS VALUES
SELECT SCAN
Hash Set API's Implemented
HSET HEXPIREAT
HEXPIRE HMGET
HINCRBY HINCRBYFLOAT
HDEL HGETDEL
HTTL HGET
HLEN HEXPIRETIME
HGETALL HKEYS
HEXISTS
Ordered Set API's Implemented
ZADD ZREM
ZINCRBY ZRANGE
ZCARD ZDIFF
ZDIFFSTORE ZINTERSTORE
ZINTERCARD ZINTER
ZPOPMIN ZPOPMAX
ZREVRANGE ZRANGEBYSCORE
ZREVRANGEBYSCORE ZREMRANGEBYLEX
ZRANGEBYLEX ZREVRANGEBYLEX
ZRANK
List API's Implemented
LLEN LPUSH
LPOP BLPOP
BRPOP LFRONT
LBACK