Skip to content

Data modeling

Choose keys so each access pattern is a GetItem, Query or transaction. DynamoDB single-table designs work unchanged.

Activate the Python environment from the quickstart. From the repository root, run:

python example/order-service/order_service.py

What is different on fdyno

On DynamoDB On fdyno Design consequence
LSIs update in the write's transaction; GSIs update asynchronously. The same. Read your own writes through the table or an LSI. A GSI read can trail a write.
Default reads are eventually consistent. Default reads are current. No need for ConsistentRead=true, and no extra cost for it.
A partition key maps to a physical partition. A partition is a contiguous range of FoundationDB keys. Query on a partition key is one range read. Contention is per item, not per partition.
Item size is billed per 1 KB / 4 KB. Items above 10,000 encoded bytes are split into chunks. Large items cost more FoundationDB reads and writes. With the default layout, every write rewrites the whole item.
Expired TTL items can linger for days. Reads use TTL plus a clock margin. TTL can model logical expiry, within your clock accuracy.
LSIs cap an item collection at 10 GB. No item-collection cap. Large partitions are allowed; FoundationDB capacity is the limit.

How a table is stored

Partition items are contiguous, in sort-key order: strings/binary sort by bytes, numbers numerically. A sort-key condition narrows the Query range; ScanIndexForward=false reverses it. Index keys append the table key, so an index partition is also one range. See storage layout.

Worked example: an order service

# Access pattern Operation
1 Get a customer profile GetItem
2 List a customer's orders, newest first Query on the customer, sort key prefix, reverse
3 Get an order with all its lines Query on the order
4 List open orders across customers Query on a GSI
5 Sign up with a unique email TransactWriteItems
6 Place an order and reserve stock TransactWriteItems

One table, app:

Entity pk sk Other attributes
Customer CUST#<id> PROFILE email, name
Order summary CUST#<id> ORDER#<date>#<orderId> status, items
Order header ORDER#<orderId> HEADER customer, status, placedAt
Order line ORDER#<orderId> LINE#<n> sku, qty
Email claim EMAIL#<email> CLAIM customer
Stock SKU#<sku> STOCK available

by_status uses status/placedAt. Only order headers have placedAt, so this sparse GSI holds one entry per order.

Place an order in one TransactWriteItems:

  1. Update SKU#A7: SET available = available - :qty, condition available >= :qty.
  2. Put the header and lines.
  3. Put the customer summary.

Insufficient stock cancels everything. On commit, by_status already holds the order. A ClientRequestToken prevents duplicate placement on retry.

Unique email: put the customer and EMAIL#<email> with attribute_not_exists(pk) in one transaction. Concurrent sign-ups have one winner. A GSI cannot enforce uniqueness; the claim item does.

Run the example

The Python and JavaScript sources implement every pattern. Python setup is above. For JavaScript:

cd example/order-service
npm install
node order_service.mjs

Both print:

sign-up: duplicate email refused: None, ConditionalCheckFailed
order 11: placed once, stock left 2
order 12: refused, nothing written, stock left 2
open orders: ORDER#11 by 42
profile: Ada ada@example.com
orders of CUST#42: ORDER#2026-03-04#11
ORDER#11: HEADER, LINE#1, LINE#2

Indexes

Design Rule
Sparse keys No index key means no entry.
Write cost Changing the index key moves the entry atomically. Changing only a projected value rewrites the entry at the same key.
Projection ALL copies the item. Project only queried attributes. Unprojected GSI attributes fail with ValidationException; LSIs fetch them from the table.
Backfill A new GSI on existing data refuses queries while CREATING. Wait for ACTIVE before deploying readers.
Key size Index key plus table key must fit FoundationDB's 10,000-byte key limit.
Composite GSI Up to four partition-key and four sort-key attributes; no synthetic concatenation needed.

GSI and LSI compared

Both kinds of index keep their entries in one part of the table's key space, under the index name. Entries sort by the index key, then by the table key. A write commits its LSI entries in the same transaction as the item, so a read through an LSI sees every write that committed before the read started, as a table read does. A GSI is updated later, from a change record that commits with the item, as in DynamoDB: a GSI read is eventually consistent (indexes). The two kinds differ in when you can create them, which keys they take and what a read can ask for.

Rule GSI LSI
Created With CreateTable, or later with UpdateTable GlobalSecondaryIndexUpdates. One index create or delete per call, and none while another index is CREATING; more return LimitExceededException Subscriber limit exceeded: Only 1 online index can be created or deleted simultaneously per table. Throughput Update entries are not limited. With CreateTable only.
Removed UpdateTable Delete, also while CREATING. While one index is CREATING, deleting another returns the same LimitExceededException, and a TableClass change returns ResourceInUseException. Only with the table.
Count 20 per table. More return ValidationException GlobalSecondaryIndex count exceeds the per-table limit of 20, from CreateTable and from UpdateTable. 5 per table. More return ValidationException LocalSecondaryIndexes must have length less than or equal to 5.
Keys 1 to 4 partition-key attributes and 0 to 4 sort-key attributes. The table's partition key and one sort-key attribute. The table must have a sort key, the index must have a sort key, and the two index keys must differ. Each rule has its own ValidationException.
Backfill An index added with UpdateTable is CREATING until the backfill ends. Until then, reads through it fail with ValidationException Cannot read from backfilling global secondary index: <name>. An index created with CreateTable is never CREATING. None. A read never checks a backfill state.
ConsistentRead: true ValidationException Consistent reads are not supported on global secondary indexes from Query and Scan; PartiQL returns ValidationException Strongly consistent read is not supported on Global Secondary Indexes. Accepted.
Read asks for an attribute the index does not project ValidationException Global secondary index <name> does not project [<attributes>]. Select: ALL_ATTRIBUTES on an index that is not ALL returns ValidationException Select type ALL_ATTRIBUTES is not supported for global secondary index <name> because its projection type is not ALL. fdyno reads the table item of each entry on the page, in the same read transaction. If the item is absent at that snapshot, the entry is left out. See what this costs.
Query filter on an attribute the index does not project ValidationException Secondary index <name> does not project one or more filter attributes: [<attributes>]. The same error.
Scan filter on an attribute the index does not project Not checked. The filter sees only the index entry, where that attribute is absent. Not checked. The filter sees only the index entry, unless the read also fetches table items; then it sees the table item.
Item collection size Not applicable. No 10 GB cap; fdyno does not return ItemCollectionSizeLimitExceededException.

See table_ops.go (createTableLSIs, UpdateTable), query_ops.go (localIndexNeedsBaseHydration, validateIndexRequestedAttributes, validateIndexQueryFilterAttributes).

What a projection costs

A GSI Query gets its result attributes from the index value. If the index does not project the TTL attribute, the TTL filter can still read the base item.

KEYS_ONLY stores the table and index keys. INCLUDE adds the attributes you select, and ALL stores the full item. If a write changes neither the index key nor the encoded projection, fdyno does not write to that index. For by_status, a change to a non-key order note can leave a keys-only entry as it is. A change of status still clears the old entry and writes a new one, also with KEYS_ONLY. See the index delta test.

A large encoded projection uses a manifest at the index key and separate chunk keys. Query reads the manifest in the index range, then issues point reads for the chunks of that entry in the same read transaction. A response projection expression does not avoid reading those chunk bytes. See the projection read tests.

When an index key moves, the old item can show two facts: the old projection was stored in one value, and the new key has no chunks. fdyno skips a range clear only where it knows that there are no chunks. When the old projection can have chunks, fdyno still clears them.

Measured payload, ALL projection Change per moved GSI entry
1 KiB Unchanged: one point clear and one set.
7,800 bytes (stored in one value) Two fewer range-clear calls.
24,000 bytes (stored in chunks) Two fewer range-clear calls; the necessary chunk writes stay.

The matched UpdateItem comparison moved every GSI key on one private Redwood cluster without LSIs or streams. The counts are issued FoundationDB mutation calls, not network requests, storage bytes or throughput gains.

fdyno does not prefetch chunks in Query. We tested it on a full page of 24,000-byte payloads. Prefetching the next entry cut the groups of chunk reads from 44 to 39, but each query still issued 132 chunk reads. The pooled handler p95 went from 14.79 ms to 13.56 ms: 8.3% lower, less than the 10% target. When the first chunk of the first entry was missing, the test version had already issued three extra reads for the next entry. The matched-pair results are from a single-host test, not an expected latency gain.

How an online GSI becomes active

When UpdateTable adds a GSI, it first checks every AttributeDefinitions entry. If an AttributeType is missing or is not S, N or B, the call fails with ValidationException. No index or backfill job exists then. UpdateTable ignores a valid definition that no key uses; CreateTable rejects it with ValidationException.

Then UpdateTable publishes CREATING with a durable backfill job. From this point, item writes also write the new index. The metadata revision stops an item write that missed the new index from committing after the index exists.

The worker scans the base keys in order. Each page reads the current items and commits their entries with the last processed key, the cursor. If an item in the scanned range changes before the page commits, the read conflict makes the page retry. After a restart, the worker continues from the committed cursor. Keys that did not fit in the last transaction stay after that cursor.

The backfill runs on the process that holds the index-backfill worker lease. A graceful stop (SIGTERM) releases the lease, with a 2-second timeout. A peer then continues the job on its next tick. If the release fails, the peer waits until the lease expires. After a crash or a SIGKILL of the holder, no process continues the backfill until the lease expires.

There is one index-backfill lease per cluster, so one process backfills every new GSI in the cluster. It runs the jobs one at a time, in an internal order that does not follow table names or creation time. Each job runs until its index is ACTIVE, or until the job fails; a failed job is retried on the next pass and does not block the others. A large backfill delays the GSIs queued after it, on any table. A crash of the holder pauses all GSI backfills in the cluster for up to one lease lifetime; a clean stop releases the lease at once.

A restore from a backup, a point-in-time restore and an import from S3 use the same queue. They write the base items only. The table becomes ACTIVE with each GSI CREATING and a backfill job, and each GSI then becomes ACTIVE as above. Until then, a Query or Scan on that GSI fails as it does on any CREATING GSI. DynamoDB returns these tables with their GSIs already ACTIVE.

There is one exception: a lease written by a clock that is far ahead. A peer can take such a lease before its stored expiry. A peer notes the lease value when it first sees it. If the value stays unchanged for at least one lease lifetime and is still far ahead, the peer takes the lease at its next check. See A clock far ahead.

The lease lifetime is 155 s for the fixed 5 s interval. Add the clock difference and one tick; see how a lease fences worker writes. The index stays CREATING during this time. No entry is lost, because each page commits its entries with the cursor.

Step What happens Index
UpdateTable Publishes CREATING with a durable backfill job. Item writes already maintain the new index. CREATING
Pages Each page reads current items and commits their entries with the cursor, the last processed key. A restart resumes from the committed cursor. CREATING
Empty scan The page scan that finds no more keys publishes ACTIVE and removes the job, in one transaction. Skipped sparse, invalid or oversized keys have no entry. ACTIVE

The worker checks the table ID and index generation before each page. A stale job cannot write to a replacement with the same name. Sparse, invalid or oversized index keys already present in the table are skipped; ACTIVE does not mean every table item has an index entry. See the backfill race tests, resume and generation tests and what to check when progress stops.

What a reader sees during a backfill

Only reads through the new GSI wait for ACTIVE. Reads of the base table, its LSIs and its other GSIs do not change.

Call While the GSI is CREATING After the GSI is deleted during its backfill
Query or Scan with IndexName ValidationException: Cannot read from backfilling global secondary index: <name> ValidationException: The table does not have the specified index: <name>
PartiQL SELECT from "table"."index" The same Cannot read from backfilling ... error ValidationException: The table does not have the specified index, without the name
DescribeTable The index with IndexStatus: CREATING and Backfilling: true The index is absent
Item writes Write the new index's entries. A write whose value for the new index's key is invalid (wrong type, an empty string or binary, or a key too long) fails with ValidationException; the backfill instead skips old items with such values Succeed without that index

At ACTIVE, Backfilling is absent from the description. A GSI created with CreateTable never shows CREATING. See query_ops.go, partiql_index.go and helpers.go.

A backfill has no failed state. Its job ends in one of two ways:

Event Result
Page scan empty ACTIVE and the job removed, in one transaction.
Table gone or replaced, index gone, new index generation, or index no longer CREATING Job removed, nothing published.
Page error A later pass resumes any remaining job from its committed cursor.

A pass runs every 5 s, and also when UpdateTable adds a job. A page error does not stop the pass. The pass goes on to the next job and reports the first error as a worker failure for index-backfill. A throttled page ends the pass. The pass then reports a failure only if an earlier job in the pass failed, and it reports that earlier error.

An error does not show that the page changed nothing. If the commit outcome is unknown, the page can have committed its entries with the cursor. An empty scan can have committed ACTIVE and the job removal. A later pass lists the jobs that remain. Each page reads its job and cursor again. So the backfill continues each job that still exists from its committed cursor.

If FoundationDB rejects a page as too large (error 2101), the page did not commit. The worker retries it at once, in the same pass, with half the row cap: 64 rows, then 32, down to one row. A page can hold fewer rows than its cap. The worker also sizes a page from the bytes of its first row. The end of the table or the scan budget can also end a page sooner.

So the retry does not always halve the rows of the failed page. If an earlier attempt of that page has an unknown outcome, the worker returns the error instead.

The backfill skips sparse, invalid and oversized index keys, so they do not keep the index in CREATING. See index_backfill.go.

So a page that fails on every pass keeps the index CREATING, and reads through it keep failing. See backfill alerts and the runbook for a stuck index. Deleting the index with UpdateTable is accepted while it is CREATING. One transaction clears its entries, their chunks and its job (table_ops.go). A new index of the same name starts a new backfill from the first item.

Item size

See the item encoding and chunk layout and the item limits.

Bound Rule
Up to 10,000 encoded bytes One FoundationDB value.
Larger 10,000-byte chunks, read in parallel.
Maximum 48,000 bytes, for the logical item and its stored encoding (item limits).

With the default layout, updating one attribute rewrites the whole item. Keep hot attributes small; put large, rarely changing data in a separate item under the same partition key. One Query reads both.

Hot items and hot partitions

Writes conflict on the same item or a range read by one of them, not merely on a shared partition key. FoundationDB moves busy ranges between storage servers, but cannot split one item.

By default, each process queues same-item writes serially; commit latency bounds their rate. A projected wait beyond the deadline fails at once with retryable, uncommitted ProvisionedThroughputExceededException. See hot items.

Shard a counter: pk = "COUNTER#views", sk = "SHARD#0" through "SHARD#<N-1>". Write a random shard; total them with one partition Query.

Transactions instead of workarounds

A strictly serializable transaction commits as one FoundationDB transaction. Use it for cross-item invariants: stock/order, uniqueness/owner, balance transfers. fdyno retries conflicts. Failed conditions cancel everything with TransactionCanceledException and a reason per action.

Bound Includes
100 actions Per transaction, as in DynamoDB.
4 MiB Request data, as in DynamoDB.
10 MB FoundationDB limit Every index entry and stream record too.

Keep transactions small: every item read can conflict. See transaction APIs and exact limits.

Time and change

Reads and conditions hide TTL-expired items by the local clock after TTL plus DYNODB_TTL_SKEW_MARGIN (default one minute). The sweeper deletes later. Keep within the clock bound.

Changes and stream records commit together; derived views/caches see no uncommitted change. Consumers must be idempotent: retries can redeliver.

Not guaranteed

A GSI does not enforce uniqueness. A new GSI is incomplete until ACTIVE. TTL visibility depends on clock accuracy; physical deletion has no deadline. Only write transactions (TransactWriteItems, PartiQL ExecuteTransaction) take a ClientRequestToken. Other writes that clients retry must be safe to repeat.

How we know: SDK client matrix.