Java bindings for FoundationDB distributed transactional key-value store with ACID guarantees, transactions, tuples, subspaces, and multi-tenancy
npx @tessl/cli install tessl/maven-com-apple-foundationdb--fdb-java@7.4.0Official Java bindings for FoundationDB, a distributed transactional key-value store with ACID guarantees. Provides high-performance access to structured data across clusters with automatic transaction retry, type-safe key encoding, and multi-tenancy support.
com.apple.foundationdb:fdb-java<dependency>
<groupId>com.apple.foundationdb</groupId>
<artifactId>fdb-java</artifactId>
<version>7.4.3</version>
</dependency>import com.apple.foundationdb.*;
FDB fdb = FDB.selectAPIVersion(740);
try (Database db = fdb.open()) {
db.run(tr -> {
tr.set("key".getBytes(), "value".getBytes());
return null;
});
}See Quick Start Guide for detailed setup instructions.
Database.run() handles transient errors automaticallyimport com.apple.foundationdb.*;
import com.apple.foundationdb.tuple.Tuple;
import com.apple.foundationdb.subspace.Subspace;
import com.apple.foundationdb.directory.DirectoryLayer;
import java.util.concurrent.CompletableFuture;| Operation | Method | Notes |
|---|---|---|
| Write | Transaction.set(key, value) | Overwrites existing value |
| Read | Transaction.get(key) | Returns CompletableFuture<byte[]> |
| Range Query | Transaction.getRange(begin, end) | Returns AsyncIterable<KeyValue> |
| Clear | Transaction.clear(key) | Removes key |
| Atomic Add | Transaction.mutate(ADD, key, param) | Little-endian integer addition |
| Commit | Transaction.commit() | Returns CompletableFuture<Void> |
| Pattern | Usage | When to Use |
|---|---|---|
| Automatic Retry | Database.run(lambda) | Most common, handles retries |
| Read-Only | Database.read(lambda) | Snapshot reads, no writes |
| Async | Database.runAsync(lambda) | Non-blocking, returns Future |
| Manual | Database.createTransaction() | Fine-grained control |
0xFF are reservedDatabase, Transaction, and Tenant objectsopen()FDB.stopNetwork() only on application shutdownReal-World Scenarios - Common patterns
Edge Cases - Advanced scenarios
Complete API documentation:
db.run(tr -> {
tr.set("key".getBytes(), "value".getBytes());
return null;
});String value = db.run(tr -> {
byte[] result = tr.get("key".getBytes()).join();
return result != null ? new String(result) : null;
});db.read(tr -> {
for (KeyValue kv : tr.getRange("prefix:".getBytes(), "prefix;".getBytes())) {
// Process key-value pair
}
return null;
});Tuple key = Tuple.from("users", 1001, "profile");
byte[] packed = key.pack();
db.run(tr -> {
tr.set(packed, "data".getBytes());
return null;
});Subspace users = new Subspace(Tuple.from("users"));
byte[] key = users.pack(Tuple.from(1001));
db.run(tr -> {
tr.set(key, "data".getBytes());
return null;
});FDB.selectAPIVersion(version) before any operationsopen()Database.run() for automatic retry on conflictsonError()FDBException.isRetryable() indicates if retry is appropriateTransaction.onError() for manual retry logic