Skip to content
IntelliStream-DataHubPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Zettuce (Zero-Copy Lettuce)

Maven Central

Website & Documentation · Client Guides · Spring Boot / Micronaut / Quarkus · Benchmarks · Production Guide

Zettuce is a high-performance, modern alternative to the Java Lettuce library for Valkey and Redis.

It replaces Lettuce's heavy Netty/Reactor stack with a single, zero-dependency C11 networking engine (zettuce-c) accessed directly through Java 22+ Panama FFM — and exposes the exact same fast engine to C, Rust, and Python.

It works over RDMA (RoCE / InfiniBand with Valkey) for single-digit microsecond latency and over standard TCP (powered by Linux io_uring with automatic epoll fallback) and Unix domain sockets (AF_UNIX) for both Valkey and Redis (since Redis has no RDMA support) — so even on plain TCP with Redis or Valkey, you get a major speedup over Lettuce.


Why Choose Zettuce Over Lettuce?

  • 4.5×–5.4× faster over RDMA — and 1.7×–2.6× faster even over plain TCP
    • Over RDMA, Zettuce bypasses the OS kernel completely for ~8 µs p50 latency and over 1.17M ops/s from Java (and 1.67M ops/s from C).
    • Over ordinary TCP, Zettuce collapses each request-response into a single Linux io_uring syscall (SEND + RECV linked in the kernel) and parses RESP2/RESP3 directly in a zero-allocation C arena—beating Lettuce 7.9.0 with native Netty Epoll by 1.67×–2.62× with less than half the p99 latency.
  • Zero dependencies & no Netty overhead
    • No Netty, no Project Reactor, no transitive dependency tree, and no event-loop thread-handoff latency or ByteBuf GC churn.
    • The entire Java client is a tiny (~90 KB) zero-dependency JAR using Java's built-in Foreign Function & Memory (FFM) API.
  • RDMA, TCP, Unix sockets, and AUTO fallback in one client
    • Use RDMA on RDMA-capable Valkey clusters (Redis has no RDMA support), TCP on standard networks/containers with Valkey or Redis, UNIX (AF_UNIX, e.g., /var/run/valkey/valkey.sock, /var/run/redis/redis.sock, or unix:///...) for co-located same-host instances, or AUTO to try RDMA first and seamlessly fall back to TCP.
    • On Linux containers where io_uring is restricted by seccomp, TCP and Unix sockets automatically fall back to epoll.
  • One consistent engine for Java, C, Rust, and Python
    • Share the exact same protocol parser, pipelined batching, Cluster routing, Sentinel discovery, Pub/Sub, and metrics across polyglot microservices (Python's C-extension releases the GIL on every round-trip and supports asyncio).
  • Built for production safety
    • Automatic session state replay on reconnect (AUTH / ACL → HELLO 3 → SELECT → CLIENT SETNAME, with in-transaction changes deferred until EXEC commits) using exponential backoff + full jitter.
    • Linearizable retry safety (SAFE_ONLY default: never blindly retries non-idempotent writes mid-flight; drops inside MULTI or after WATCH never silently reconnect—every command fails until EXEC/DISCARD or explicit reconnect()), unsolicited RESP3 push handling (CLIENT TRACKING), and blocking-command timeout desync protection.
    • Per-command error values inside pipelined batches and MULTI/EXEC (Java ValkeyCommandException, Rust Value::Error(String), Python ValkeyCommandError) so a single failed command never hides sibling results.
    • Bounded connection pools (evicting any connection whose session state changed or that was left in MULTI/WATCH; Java pool.borrow() returns a single-use lease), per-node locked Cluster failover (MOVED/ASK/TRYAGAIN/CLUSTERDOWN) with caller-owned replies, Sharded Pub/Sub (SSUBSCRIBE/SPUBLISH), built-in metrics, ASan/UBSan/100k-iteration parser fuzzing, and a 5-scenario Jepsen linearizability & chaos suite.

Platform Support (Native Linux Engine + Pure-Java Dev Fallback): Zettuce's native C11 engine (zettuce-c) targets Linux x86_64 and aarch64 (ARM64) for RDMA verbs (libibverbs/librdmacm), Linux io_uring, epoll, and AF_UNIX sockets. On Linux servers/containers without librdmacm1/libibverbs1 installed, TCP, UNIX, and AUTO transports still run on the native C11 io_uring/epoll engine (Zettuce.isNativeAvailable() == true, Zettuce.isRdmaAvailable() == false).

Prebuilt Maven Central Binaries, Non-Linux Dev Machines & Older Distros (RHEL 9, Debian 12): Prebuilt native libraries bundled in ai.intellistream.zettuce:zettuce-java target Linux x86_64 and aarch64 (ARM64) on glibc 2.38+ (such as Ubuntu 24.04+, RHEL 10+, Debian 13+, and Fedora 44+). On macOS/Windows dev workstations or older-glibc Linux hosts (RHEL 9 / Debian 12) where the bundled .so cannot load, zettuce-java automatically falls back to a zero-dependency pure-Java TCP/Unix RESP2/RESP3 backend for TCP, AUTO, and UNIX transports so development and tests work out of the box. For full native C11 performance on RHEL 9 or Debian 12, build zettuce-c from source on that platform (make -C zettuce-c) and either run make java locally or pass -Dlettuce.rdma.library.path=/path/to/libvalkey_rdma_ffm.so to the JVM.

Transport Encryption & Dynamic Credentials: Zettuce supports TLS 1.2 / 1.3 and mTLS over TCP (TlsOptions, FULL/CA_ONLY/NONE verification, SNI + IP SAN checking, loaded dynamically from system OpenSSL via dlopen in C/Rust/Python/Java-FFM with a zero-dependency JSSE fallback in Java) as well as dynamic credential rotation (CredentialsProvider / valkey_rdma_cred_cb_t) invoked on every connect and reconnect. Enabling TLS refuses cleartext downgrade to RDMA or Unix sockets. Valkey-over-RDMA itself remains cleartext (matching upstream valkey-rdma); always run RDMA on isolated private networks or encrypted links (IPsec / WireGuard / MACsec).

Read-from-Replicas & Live Sentinel Failover: All four clients support ReadFrom policies (MASTER, MASTER_PREFERRED, REPLICA_PREFERRED, REPLICA, ANY, LOWEST_LATENCY with EWMA RTT tracking) across Valkey Cluster (automatic READONLY/READWRITE and WATCH/MULTI/SCAN master pinning), standalone Master-Replica pools (INFO REPLICATION discovery or static replicas), and live Sentinel failover pools backed by a native background watcher (+switch-master Pub/Sub + periodic polling fallback).

Cluster Scaling: ValkeyRdmaClusterClient / ClusterClient supports configurable per-node connection pools (connectionsPerNode 1–16 for hot-shard parallelism), shard-grouped Cluster pipelining (cluster.batch()) with transparent mid-batch MOVED/ASK redirect handling, cross-slot scatter-gather mget/mset/del, optional periodic background CLUSTER SLOTS topology refresh, and pure-Java Cluster fallback parity on macOS/Windows/older-glibc hosts.

Observability & Client-Side Caching: Zero-dependency fixed-footprint LatencyHistogram (100 ns–>60 s; lock-free in Java and Rust, thread-safe in Python), zero-overhead CommandListener tracing SPI + built-in LatencyRecorder in Java (ValkeyRdmaConnection, ValkeyRdmaBatch, ValkeyRdmaClusterClient), optional Micrometer & OpenTelemetry integration (zettuce-observability), and RESP3 CLIENT TRACKING client-side caching (ZettuceClientCache / ClientCache) with push-safe PING heartbeats (send_ping / poll_push), race-free epoch guards, and automatic disconnect-flush safety.

Expanded Commands, Pluggable Codecs, Java Frameworks & GraalVM Native Image: Full typed support across Java, Rust, and Python for Geo, HyperLogLog, Bitmaps, Valkey Functions & Scripting, Streams Consumer Groups, Scans, Hash Field Expiry, and ACL; pluggable Java ZettuceCodec<K, V> (StringCodec, ByteArrayCodec, Utf8ByteBufferCodec, ZettuceTypedConnection, ZettuceTypedPool, ZettuceClientCache.forTyped); first-class zettuce-spring (RedisConnectionFactory, RedisTemplate, StringRedisTemplate, @Cacheable via RedisCacheManager, Spring Boot AutoConfiguration, Actuator HealthIndicator) and zettuce-micronaut (@Cacheable/@CachePut/@CacheInvalidate via ZettuceSyncCache/ZettuceAsyncCache/ZettuceCacheManager, ZettuceTemplate<K, V>, Management HealthIndicator); plus built-in GraalVM 25+ Native Image reachability metadata (reachability-metadata.json + native-image.properties).

See PRODUCTION.md for deployment tuning, security/TLS notes, observability, and operational guidelines.


Benchmark Results (Two-Server Valkey 9.2.0)

Measured across two physical AlmaLinux 10.2 servers (Linux 6.12) connected over a Mellanox ConnectX-3 RoCE link (mlx4_0, 10.99.99.42 → 10.99.99.41) against Valkey 9.2.0 (valkey-rdma.so on port 6379, TCP on port 6380). Lettuce benchmarked with io.lettuce:lettuce-core:7.9.0.RELEASE + netty-transport-native-epoll:4.2.17.Final (native Epoll verified active) on OpenJDK 25.

Java 25 Head-to-Head: Zettuce RDMA vs Zettuce TCP (io_uring) vs Lettuce 7.9.0 (Epoll TCP)

Zettuce vs Lettuce 7.9.0 benchmark bar charts

Full Java 25 head-to-head table
Workload Lettuce 7.9.0 (Netty Epoll TCP) Zettuce Java TCP (io_uring) Zettuce Java RDMA Zettuce TCP vs Lettuce Zettuce RDMA vs Lettuce
PING (pipe=1) 23,661 ops/s (38.22 µs p50 / 81.12 µs p99) 41,665 ops/s (23.55 µs p50 / 36.81 µs p99) 121,371 ops/s (7.98 µs p50 / 9.72 µs p99) 1.76× (2.20× lower p99) 5.13× (8.35× lower p99)
GET 64B (pipe=1) 22,480 ops/s (41.72 µs p50 / 77.28 µs p99) 37,562 ops/s (25.47 µs p50 / 40.88 µs p99) 111,023 ops/s (9.22 µs p50 / 11.28 µs p99) 1.67× (1.89× lower p99) 4.94× (6.85× lower p99)
SET 64B (pipe=1) 21,833 ops/s (42.82 µs p50 / 78.60 µs p99) 32,431 ops/s* (30.02 µs p50 / 47.98 µs p99) 101,567 ops/s (10.05 µs p50 / 11.84 µs p99) 1.49×* 4.65× (6.64× lower p99)
GET 1 KiB (pipe=1) 22,334 ops/s (42.83 µs p50 / 78.35 µs p99) 32,612 ops/s* (30.15 µs p50 / 47.91 µs p99) 101,221 ops/s (9.79 µs p50 / 12.28 µs p99) 1.46×* 4.53× (6.38× lower p99)
PING (pipe=16) 198,541 ops/s (73.98 µs p50) 469,303 ops/s (33.30 µs p50) 1,070,601 ops/s (14.70 µs p50) 2.36× 5.39×
GET 64B (pipe=16) 197,253 ops/s (72.88 µs p50) 357,353 ops/s* (43.07 µs p50) 722,973 ops/s (21.31 µs p50) 1.81×* 3.67×
GET 64B (pipe=64) 259,024 ops/s (225.95 µs p50) 678,387 ops/s (84.84 µs p50) 1,171,494 ops/s (55.10 µs p50) 2.62× 4.52×
8-Thread GET 64B 113,843 ops/s (shared) / 158,113 (8-conn) 168,596 ops/s* (44.66 µs p50) 474,246 ops/s (15.88 µs p50) 1.48× / 1.07×* 4.17× / 3.00×

*Measured on Zettuce's epoll TCP path before the io_uring upgrade (io_uring adds another ~8–9% on pipe=1).

Cross-Language Performance (Valkey 9.2.0, Two Servers)

Cross-language Zettuce RDMA benchmark bar charts

Full cross-language numbers table
Client RDMA PING p=1 RDMA GET 64B p=1 RDMA Pipelined Zettuce TCP PING p=1 Zettuce TCP Pipelined
C (zettuce-c) 107,580 ops/s (8.54 µs) — 1,674,872 ops/s (p=64) 41,600 ops/s (23.58 µs, io_uring) 1,224,387 ops/s (p=64, io_uring)
Java 25 (zettuce-java) 121,371 ops/s (7.98 µs) 111,023 ops/s (9.22 µs) 1,171,494 ops/s (GET p=64) 41,665 ops/s (23.55 µs, io_uring) 678,387 ops/s (GET p=64)
Rust (zettuce-rs) 96,077 ops/s (10.00 µs) 87,699 ops/s (10.74 µs) 780,881 ops/s (p=16) 32,154 ops/s (30.19 µs) 389,556 ops/s (p=16)
Python (py-zettuce) 97,338 ops/s (9.33 µs) 88,930 ops/s (10.73 µs) 860,728 ops/s (p=16) 31,417 ops/s (30.81 µs) 372,675 ops/s (p=16)

Native InfiniBand (56G FDR) vs. RoCE v1 (56 GbE)

Measured back-to-back on the same dual-port ConnectX-3 HCA (mlx4_0 port 1 native 56G FDR InfiniBand vs. port 2 56 GbE RoCE v1) against Valkey 9.2.0: native InfiniBand shaves ~0.55–0.70 µs off small-command latency (7.18 µs p50 / 3.63 µs min / 129,040 ops/s Java 25 PING p=1; 7.91 µs p50 / 124,281 ops/s C11 PING p=1; 1,860,195 ops/s C11 PING p=64), while heavier commands (GET/SET) perform within ~1–3% across both fabrics.


Quick Examples

Java 22+ (Zero-Dependency FFM)

Available on Maven Central (bundles Linux x86_64 and aarch64 native libraries for glibc 2.38+):

<dependency>
    <groupId>ai.intellistream.zettuce</groupId>
    <artifactId>zettuce-java</artifactId>
    <version>0.9.3</version>
</dependency>
// Gradle (Kotlin DSL)
implementation("ai.intellistream.zettuce:zettuce-java:0.9.3")

To restrict Panama FFM native access exclusively to Zettuce (instead of ALL-UNNAMED), place zettuce-java on the module path (-p):

java -p /path/to/zettuce-java-0.9.3.jar --add-modules ai.intellistream.zettuce \
  --enable-native-access=ai.intellistream.zettuce \
  -cp your-app.jar com.example.Main

(For classpath or fat-JAR launches where all classes are in the unnamed module, pass --enable-native-access=ALL-UNNAMED.)

import ai.intellistream.zettuce.*;

// Connect over RDMA, plain TCP (io_uring/epoll), or AUTO (RDMA -> TCP fallback)
RdmaConnectionOptions opts = RdmaConnectionOptions.builder()
        .transport(RdmaConnectionOptions.Transport.AUTO)
        .tcpFallbackPort(6380)
        .auth("my-secret")
        .respVersion(3)
        .database(0)
        .clientName("orders-service")
        .build();

try (ValkeyRdmaConnection conn = Zettuce.connect("10.99.99.41", 6379, opts)) {
    conn.set("user:42", "alice");
    String val = conn.get("user:42");

    // Pipelined batch in a single RDMA doorbell / TCP write
    ValkeyRdmaBatch batch = conn.batch();
    batch.get("user:42");
    batch.ping();
    var replies = batch.execute();

    System.out.println("Transport=" + conn.activeTransport() + " metrics=" + conn.metrics());
}

// Thread-safe async CompletableFuture facade for Netty / Micronaut / Spring / Quarkus
try (ValkeyRdmaPool pool = Zettuce.pool("192.0.2.41", 6379, 32, opts)) {
    ValkeyRdmaAsyncCommands async = pool.async(); // or pool.async(blockingExecutor)
    String val = async.get("user:42").join();
}

Python 3.10+ (METH_FASTCALL, GIL-releasing)

from zettuce import ValkeyRdmaClient, RdmaOptions

opts = RdmaOptions.auto(tcp_fallback_port=6380)  # or RdmaOptions.tcp() / RdmaOptions.low_latency()
with ValkeyRdmaClient("10.99.99.41", 6379, opts).connect() as conn:
    conn.set("user:42", "alice")
    print(conn.get("user:42"), conn.metrics())

Rust

use zettuce::{Client, RdmaOptions};

let opts = RdmaOptions::auto(6380); // or RdmaOptions::tcp() / RdmaOptions::low_latency()
let mut conn = Client::with_options("10.99.99.41", 6379, opts).connect()?;
conn.set("user:42", "alice")?;
println!("{:?}", conn.get("user:42")?);

Repository Modules

Module Language / Binding Key Capabilities
zettuce-c/ C11 (libzettuce.so / libvalkey_rdma_ffm.so) Valkey-over-RDMA RC QP (IBV_WR_RDMA_WRITE_WITH_IMM, IBV_SEND_INLINE, 64-WR batched RQ), zero-dep Linux io_uring + epoll TCP engine, AUTO fallback, pointer-stable slab RESP2/3 parser, session replay, thread-safe Cluster (MOVED/ASK/TRYAGAIN), Pub/Sub & Sharded Pub/Sub, Sentinel (AUTO), observability metrics, 100k-iteration parser fuzzer, ASan/UBSan target
zettuce-java/ Java 22+ FFM (ai.intellistream.zettuce:zettuce-java) Zero-dependency Panama FFM client (Zettuce, ValkeyRdmaConnection, ValkeyRdmaBatch, bounded ValkeyRdmaPool, ValkeyRdmaClusterClient, ValkeyRdmaMasterReplicaPool, ValkeyRdmaSentinelPool, ZettuceClientCache, LatencyHistogram, CommandListener, ZettuceCodec<K, V>, ZettuceTypedConnection/ZettuceTypedPool, GraalVM 25 Native Image metadata)
zettuce-observability/ Java (ai.intellistream.zettuce:zettuce-observability) Optional Micrometer ZettuceMicrometerBinder (per-command Timer + pool/cache gauges), OpenTelemetry ZettuceOpenTelemetryListener (SpanKind.CLIENT DB spans), and CompositeCommandListener
zettuce-spring/ Java (ai.intellistream.zettuce:zettuce-spring) Spring Data Redis ZettuceConnectionFactory & ZettuceRedisConnection unlocking RedisTemplate, StringRedisTemplate, and @Cacheable (RedisCacheManager), plus Spring Boot AutoConfiguration & Actuator ZettuceHealthIndicator
zettuce-micronaut/ Java (ai.intellistream.zettuce:zettuce-micronaut) Micronaut SyncCache / AsyncCache (ZettuceCacheManager, ZettuceCacheConfiguration) unlocking @Cacheable/@CachePut/@CacheInvalidate, ergonomic ZettuceTemplate<K, V>, and Management ZettuceHealthIndicator
zettuce-rs/ Rust (zettuce-rs / use zettuce::*) Zero runtime dependencies—statically links zettuce-c with hidden symbol visibility (no external .so required; opt-in ZETTUCE_LIB_DIR override) exposing Client, Connection, Batch, bounded Send + Sync Pool, ClusterClient, PubSub, Sentinel, Metrics
py-zettuce/ Python 3.10+ (py-zettuce / import zettuce) Native CPython METH_FASTCALL extension statically linked against zettuce-c (no external .so required), releasing the GIL on every RTT + asyncio support (AsyncValkeyRdmaConnection, AsyncValkeyRdmaPool)
tests-jepsen/ Jepsen Chaos & Linearizability Exact Wing & Gong linearizability checker (Register, AtomicCounter, MutexLock), Nemesis fault injection (DROP_ALL, RX fragmentation, SIGKILL/restart, live MOVED/ASK flips), and cross-language consistency verification

Building & Testing

Prerequisites

  • Linux (x86_64 or aarch64 / ARM64) with gcc/C11, make, and RDMA development headers (libibverbs-dev on Debian/Ubuntu or rdma-core-devel on RHEL/AlmaLinux/Fedora) when building from source. RDMA runtime libraries (libibverbs.so.1, librdmacm.so.1) are loaded via dlopen—TCP and Unix modes work even on machines without RDMA hardware or RDMA runtime packages (and prebuilt Maven Central JARs—as well as Linux x86_64/aarch64 wheels built in CI—need neither a compiler nor RDMA headers).
  • JDK 22+ & Maven for zettuce-java
  • Rust (rustc/cargo) for zettuce-rs (compiles and statically links zettuce-c via the cc build dependency with zero runtime dependencies; set ZETTUCE_LIB_DIR only if you want to link a custom prebuilt libvalkey_rdma_ffm.{a,so})
  • Python 3.10+ dev headers (python3-devel / python3-dev) for building py-zettuce from source (statically links zettuce-c into _zettuce_ext)

Build & Verify

# Build all 4 modules (C, Java, Rust, Python)
make

# Build only the C engine (e.g. for RHEL 9 / Debian 12 or custom glibc targets)
make -C zettuce-c
# Then either package the Java JAR locally with `make java`, or point the JVM to it:
#   java -Dlettuce.rdma.library.path=$PWD/zettuce-c/build/libvalkey_rdma_ffm.so ...

# Cross-compile ARM64 alongside x86_64 for a multi-arch Java JAR (requires gcc-aarch64-linux-gnu)
make -C zettuce-c all-arches && mvn -f zettuce-java/pom.xml package

# Run all language suites + 100k RESP fuzzer + 5-scenario Jepsen suite
make test

# Run AddressSanitizer + strict UndefinedBehaviorSanitizer + LeakSanitizer
make -C zettuce-c check-asan

# Target a specific RDMA interface IP (auto-detected from /sys/class/infiniband if unset)
VALKEY_RDMA_HOST=10.99.99.41 make test

Multi-Server Valkey 9.2.0 Benchmarking

Start valkey-server with valkey-rdma.so on Server A (<server-ip>):

valkey-server --loadmodule /path/to/valkey-rdma.so \
  --rdma-bind <server-ip> --rdma-port 6379 \
  --bind <server-ip> --port 6380 \
  --protected-mode no --save "" --appendonly no

Then benchmark from Server B:

# Pure C RDMA benchmark
./zettuce-c/build/rdma_c_bench <server-ip> 6379 100000 1

# Rust RDMA vs TCP benchmark
cargo run --release --manifest-path zettuce-rs/Cargo.toml --example bench -- <server-ip> 6379 100000 6380

# Python C-extension RDMA vs TCP benchmark
PYTHONPATH=py-zettuce python3 py-zettuce/benchmarks/bench.py <server-ip> 6379 100000 6380

License

Licensed under the Apache License, Version 2.0 — see LICENSE for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages