ConfigsApr 16, 2026·3 min read

FoundationDB — Distributed Key-Value Store by Apple

A multi-model distributed database with ACID transactions, used in production at Apple to power iCloud and other services at massive scale.

TL;DR
Multi-model distributed database with ACID transactions, used at Apple scale. Open-sourced with strong consistency guarantees.
§01

What it is

FoundationDB is a distributed key-value store with full ACID transactions across multiple keys and multiple machines. Originally acquired by Apple, it was open-sourced in 2018 and powers critical Apple services including iCloud at massive scale.

FoundationDB provides an ordered key-value API as its foundation, with higher-level data models (document, relational, graph) built as layers on top. This layered architecture lets you choose the data model that fits your application.

§02

How it saves time or tokens

Most distributed databases sacrifice consistency for availability or performance. FoundationDB provides serializable transactions without giving up horizontal scalability. This means application code does not need complex conflict resolution, eventual consistency workarounds, or compensation logic.

The simulation testing framework (used internally by Apple) catches bugs that would only appear in production under specific failure scenarios. This reduces debugging time significantly for distributed system developers.

Additionally, the project's well-structured documentation and active community mean developers spend less time troubleshooting integration issues. When AI coding assistants generate code for this tool, they can reference established patterns from the documentation, producing correct implementations with fewer iterations and lower token costs.

§03

How to use

  1. Install FoundationDB server and client:
# On macOS
brew install foundationdb

# On Ubuntu
curl -LO https://github.com/apple/foundationdb/releases/download/7.3.0/foundationdb-clients_7.3.0-1_amd64.deb
sudo dpkg -i foundationdb-clients_7.3.0-1_amd64.deb
  1. Connect and perform basic operations:
import fdb
fdb.api_version(730)

db = fdb.open()

@fdb.transactional
def set_greeting(tr, name, greeting):
    tr[fdb.tuple.pack(('greetings', name))] = greeting.encode()

@fdb.transactional
def get_greeting(tr, name):
    return tr[fdb.tuple.pack(('greetings', name))]

set_greeting(db, 'Alice', 'Hello')
print(get_greeting(db, 'Alice'))  # b'Hello'
  1. Use the @fdb.transactional decorator for automatic retry on conflicts.
  1. Scale by adding more FoundationDB processes to the cluster.
§04

Example

# Atomic counter with ACID guarantees
@fdb.transactional
def increment(tr, counter_key):
    current = tr[counter_key]
    value = int(current) if current else 0
    tr[counter_key] = str(value + 1).encode()
    return value + 1
§05

Related on TokRepo

§06

Common pitfalls

  • Treating FoundationDB like a document database. It is a low-level ordered key-value store. You need to design your key layout carefully for efficient range reads and avoid hotspots.
  • Exceeding the 10MB transaction size limit. FoundationDB transactions are limited to 10MB of mutated data. Large bulk operations need to be split into smaller transactions.
  • Not using the tuple layer for key construction. Raw byte keys are error-prone. The tuple layer provides ordered, type-safe key encoding.
  • Failing to review community discussions and changelogs before upgrading. Breaking changes in major versions can disrupt existing workflows. Pin versions in production and test upgrades in staging first.

Frequently Asked Questions

Why did Apple open-source FoundationDB?+

Apple acquired FoundationDB in 2015 and open-sourced it in 2018. The open-source release allows the broader community to build layers and tools on top of the core key-value store while Apple continues to use it internally for iCloud and other services.

What are FoundationDB layers?+

Layers are higher-level data models built on the ordered key-value API. Examples include the Record Layer (relational), Document Layer (MongoDB-compatible), and graph databases. Each layer maps its data model to ordered key-value pairs with ACID transaction guarantees.

How does FoundationDB achieve ACID transactions at scale?+

FoundationDB uses an optimistic concurrency control protocol with a centralized transaction manager. Transactions are serializable and automatically retried on conflict. The architecture separates storage, transaction processing, and coordination for independent scaling.

What is the simulation testing framework?+

FoundationDB includes a deterministic simulation framework that tests the entire database under thousands of failure scenarios (network partitions, disk failures, process crashes). This approach has found bugs that traditional testing misses and is considered a key reason for FoundationDB's reliability.

Can FoundationDB replace MongoDB or PostgreSQL?+

FoundationDB operates at a lower level than MongoDB or PostgreSQL. It provides a key-value API, not a query language. The Record Layer and Document Layer add higher-level interfaces, but most teams use FoundationDB when they need strong consistency guarantees at scale and are willing to build application-specific data access patterns.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets