Claude-skill-registry fdb-layer-engineering
Guide for building FoundationDB layers in Rust. Use when designing
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/fdb-layer-engineering" ~/.claude/skills/majiayu000-claude-skill-registry-fdb-layer-engineering && rm -rf "$T"
manifest:
skills/data/fdb-layer-engineering/SKILL.mdsource content
FoundationDB Layer Engineering
Patterns for building robust FDB layers with the
foundationdb crate.
Transaction Limits
| Resource | Target | Hard Limit |
|---|---|---|
| Duration | <1 sec | 5 sec (MVCC window) |
| Transaction size | <8 MB | 10 MB |
| Key size | — | 10 KB |
| Value size | — | 100 KB |
| Batch size | 100-1000 records | — |
Keep transactions short—autothrottle can't rate-limit large transactions effectively.
Transaction Rules
| Rule | Details |
|---|---|
Always use | Handles retry loop with exponential backoff |
| Design for OCC | Conflicts detected at commit, not during reads |
| Automatic idempotency | FDB 7.3+: use |
| Use Batch priority | Set for background jobs |
| Idempotent writes | Generate unique IDs OUTSIDE retry loop |
Critical Error Codes
| Code | Name | Action |
|---|---|---|
| 1007 | | Retry—exceeded 5s limit |
| 1020 | | Retry—conflict detected |
| 1021 | | May have committed—check |
| 2101 | | Reduce size (non-retryable) |
Key Design Patterns
- Tuple layer: Always use
/pack()
for order-preserving keysunpack() - Subspaces: Isolate tenant data in contiguous key ranges
- Sharded counters: Split hot keys across multiple shards
- Snapshot reads:
to skip conflict rangetrx.get(key, true)
Hotspot Prevention
| Technique | When to Use |
|---|---|
| Salting | Prepend hash prefix to distribute sequential writes |
| Reversed numbers | for latest-first ordering |
| Avoid monotonic keys | Sequential IDs/timestamps hotspot single storage nodes |
Atomic Operations
| Operation | Use Case |
|---|---|
| Counters (conflict-free increments) |
/ | High/low watermarks |
| Ordered logs, event sourcing |
| Conditional deletion |
Secondary Indexes
- Index key format:
(index_prefix, indexed_value, primary_key) - Always update indexes in same transaction as primary data
- Covering indexes store full value to avoid second lookup
Decision Matrix
| Scenario | Strategy |
|---|---|
| Single record CRUD | One txn, <100ms |
| Bulk import (100s) | Batched, 100-200 records/txn |
| Bulk import (millions) | Batched + continuation + Batch priority |
| Read then external API | Separate transactions |
| Hot key | Atomic ops or sharding |
| Background job | Batched + Batch priority |
Anti-patterns
- Long transactions - Break large ops into continuations
- Holding txn during external calls - Separate read and write transactions
- Fixed batch sizes - Use size-aware batching (~1MB per batch)
- Ignoring
- Causes duplicate side effects on retrymaybe_committed - Hot keys without sharding - Shard frequently updated keys
- Atomic ops + reads on same key - Loses conflict-free benefit
- Low-level
- Useget_range
/get_ranges
insteadget_ranges_keyvalues
Full Reference
- FDB Developer Guide: https://apple.github.io/foundationdb/developer-guide.html
- FDB Known Limitations: https://apple.github.io/foundationdb/known-limitations.html
- Automatic Idempotency (7.3+): https://pierrezemb.fr/posts/automatic-txn-fdb-730/
- HBase Data Model: https://pierrezemb.fr/posts/hbase-data-model/
- Reverse Number Scanning: https://pierrezemb.fr/posts/reverse-number-scanning/