Skip to content

What a synchronous secondary index costs

A synchronous index removes index propagation lag, but every write pays for every index entry it moves. On EC2, PutItem fell from 40,806/s with no index to 4,731/s with ten ALL indexes whose keys moved. It kept 34,640/s, about 85%, with ten KEYS_ONLY indexes whose keys did not move (a pre-v0.1 build with default cluster version 3; run aws-20261118-cliffs-gsi).

One write, one transaction

DynamoDB documents GSI reads as eventually consistent. A query on the index can miss a write that the table already acknowledged. fdyno writes the index in the same transaction. A normal item write reads the old item and works out which index entries change. It puts the item and every changed entry into one FoundationDB transaction.

  • After a write succeeds, every ACTIVE index already reflects it. There is no separate index propagation lag. Every read sees one fresh snapshot.
  • Every fdyno process sees the same committed index state, because there is no per-process copy.
  • A crash cannot lose queued index work, because there is no queue.

fdyno still rejects ConsistentRead=true on a GSI query, because that request is invalid in the DynamoDB API. Table and index are committed together, so a read sees both at the same version.

A PutItem on a table with N global secondary indexes commits one transaction. It holds the item and, for each index whose key moves, a clear of the old entry and a set of the new one. An index whose key and projection are unchanged gets no mutation.

The figure's mutation rules come from the calls and futures by route and what a projection costs.

Which index entries change

fdyno compares the old item with the new one, index by index:

The write changes Mutations for that index
The index key (the item moves in the index) Clear the old entry, set the new one
A projected attribute, but not the index key Set the entry again
Neither the key nor anything projected None

That last row is why projection matters. A KEYS_ONLY entry stores only the table and index keys, so a change to a non-key attribute issues no mutation for it. An ALL entry stores the whole item, so almost any change rewrites it. The data modeling guide has a worked orders example.

The measured cost

One EC2 sweep measured PutItem throughput with 256 clients as GSIs were added. Each point is the median of three 45 s trials with zero client errors. Six i4i.xlarge storage hosts, three log hosts, Redwood, three c7i.xlarge API hosts.

The first two indexes cost the most. The first ALL index whose key moves cost about a third of the throughput. The second cost a larger share of what remained (36% then 43%, by our arithmetic). With ten, the rate was under an eighth of the no-index rate.

Keeping the key helps little with ALL. With ten ALL indexes, writes that kept every index key reached 7,086/s against 4,731/s when every key moved. An ALL entry is still set again whenever the write changes any projected attribute; the record does not say which attributes these writes changed.

Projecting only keys almost erases the cost when the keys stay put. Ten KEYS_ONLY indexes with keys kept reached 34,640/s: about 85% of the no-index rate. Those writes issue no index mutation.

One caveat from the record: the key-kept trials ran on the same tables after the key-moving trials. The first trial of each key-kept point behaved like a key move (4,034/s for ALL, 4,585/s for KEYS_ONLY). The medians include all three trials. The KEYS_ONLY comparison exists only at ten indexes.

The transaction has a size

All of this goes into one transaction. FoundationDB bounds it at 10,000,000 affected bytes, counting written keys and values plus conflict ranges. A transaction is never split. With many ALL indexes and stream images, a request under fdyno's 4 MiB write-data limit can still exceed it. Each ALL projection, stream image and PITR old image carries its own copy of the item. Each INCLUDE projection carries its selected attributes.

Index work is also not separately provisioned. In DynamoDB, a GSI has its own write capacity, and an under-provisioned index can throttle its table. In fdyno the caller waits for the larger commit.

Adding an index to a live table

A new index on a table with data cannot be written in one transaction. fdyno builds it online. A reader must never see it ACTIVE before it is complete.

Online GSI build. UpdateTable publishes the index as CREATING with a durable backfill job; from that moment live writes maintain the index. A worker scans base keys in order, page by page, committing entries with a cursor. A write into the page being scanned forces that page to retry. A restart resumes from the committed cursor. When the scan finds nothing left, the index becomes ACTIVE and the job is removed.

  1. Live writes maintain the index from the first moment. UpdateTable publishes the index as CREATING together with a durable job. A write that read the old metadata missed the new index. The table's metadata revision stops it from committing after the index exists.
  2. Each page reads what it writes. A page reads the current items. It commits their entries together with the last key it processed. A concurrent write into that range makes the page conflict and retry. So a page cannot overwrite a newer entry with an older one.
  3. Progress is durable. The cursor commits with the entries. A restart, or another worker, resumes from it.
  4. Stale workers cannot write into a replacement. Before each page, the worker checks the table ID and the index generation.

ACTIVE means the scan completed, not that every item has an entry. Items whose index key is missing, invalid or oversized are skipped, as in DynamoDB's sparse indexes. fdyno rejects reads from a CREATING index. If it stays CREATING, the runbook has what to check.

The TLA+ index backfill model checks that an online GSI matches the table at ACTIVE, within its bounds. The deterministic simulator interleaves writes with backfill pages, lease elections and commit errors. At run time, fdyno samples one index page in 256 against the base items.

What to do with this

A synchronous index trades write throughput for the absence of index lag. Before you add one, count the entries each hot write will move, not the number of indexes. Project only the attributes your queries read, and keep index keys stable on hot writes. In this sweep, ten KEYS_ONLY indexes with stable keys kept about 85% of the no-index rate (34,640/s). Ten ALL indexes with moving keys kept about 12% (4,731/s), by our arithmetic. Those two runs change both projection and key motion.