TwiceToldby Develoker
ConceptsSystem designLabsCheat sheetsAbout

Develoker makes free tools for learning to build software. TwiceTold explains each idea twice, as an everyday analogy and the real thing; CloudArch lets you design cloud systems and put load on them.

About ยท Labs ยท Cheat sheets ยท Learning paths

โ† Back to Amazon DynamoDB

๐Ÿ“Œ Amazon DynamoDB: cheat sheet

๐ŸŽจ The analogyA hall of pinboards where each card goes on the board its name picks, so finding one name is quick.
๐ŸŽ“ The regular explanationA fully managed key-value and document database. Items are spread across partitions by a hashed partition key, so reads and writes by key stay fast at any size, as long as the keys are designed around the queries you'll run.
Partition keys pick the partitionStep 5 of 5
๐Ÿ“Œ Orders hallBoard 0B1key ben / 2026-06-02: B101234Board 1 ยท Ana, by dateA1key ana / 2026-06-01: A10A2key ana / 2026-06-15: A21234Board 2C1key cat / 2026-06-03, giftWrap: C1โœฆโœฆโœฆโœฆโœฆ01234๐ŸชShop๐Ÿง‘โ€๐Ÿ’ผSteward
  1. The Orders hall pins its cards on three boards. You never walk up to them yourself; you hand every card to the steward at the door.
  2. The shop hands in Ana's first card. The steward reads the name, applies the fixed rule and pins it on board 1.
  3. Ben's card has a different name, so the same rule sends it to a different board.
  4. Ana orders again. Same name, so same board, and the card hangs right after her first one because its date is later.
  5. Cat's card mentions gift wrap and the others don't. That's fine; only the name and date have to be there.
Query one partition, or Scan them allStep 4 of 4
๐Ÿ“Œ Orders hallBoard 0 ยท read allB1key ben / 2026-05-20: B10B2key ben / 2026-06-10: B21234Board 1 ยท read allA1key ana / 2026-05-02: A10A2key ana / 2026-06-01: A21A3key ana / 2026-06-15: A3234Board 2 ยท read allC1key cat / 2026-06-03: C101234๐ŸชShoppaid for 6๐Ÿง‘โ€๐Ÿ’ผSteward
  1. The boards already hold cards. Ana's three cards hang together on board 1, in date order.
  2. The shop asks the steward for Ana's cards from June. That's one board and one column, so just those two cards come back.
  3. Now the shop asks for every card that mentions a red scarf. The name can't help, so the steward has to read along every board.
  4. Only one card matched, but all six were read, and the hall charges for every one. Pick names and dates that turn your questions into quick errands.
A hot partition keyStep 4 of 4
๐Ÿ“Œ Orders hallBoard 0B1key ben: B10S#1key SALE#1: S#1โœฆโœฆโœฆโœฆโœฆ1234Board 1A1key ana: A10S1key SALE: S11S2key SALE: S22S3key SALE: S33S#2key SALE#2: S#2โœฆโœฆโœฆโœฆโœฆ4Board 2C1key cat: C10S#3key SALE#3: S#3โœฆโœฆโœฆโœฆโœฆ1234๐ŸชShop๐Ÿง‘โ€๐Ÿ’ผSteward
  1. On a normal day, cards carry lots of different names, so all three boards share the work.
  2. A big sale starts, and the shop writes every sale card under one name, "Sale". They all go to board 1.
  3. Board 1 can only take so many cards a second. The steward tells the shop to come back in a moment, while boards 0 and 2 stand idle.
  4. The fix is in the names. The shop writes Sale 1, Sale 2 and Sale 3, and the cards spread over all three boards. To read the sale back, it asks for all three names.
A global secondary indexStep 5 of 5
Name boardsA1key ana, PENDING: A10B1key ben, PENDING: B11A2key ana, PENDING: A2234Status boardpA1key PENDING / ana: pA10pB1key PENDING / ben: pB11pA2key PENDING / ana: pA2โœฆโœฆโœฆโœฆโœฆ234๐ŸชShop๐Ÿ“ฆPacking team
  1. The shop hands in two new cards. They're pinned in the Orders hall as usual, by name.
  2. A runner copies a summary of each card onto the status board, arranged by status instead of name.
  3. The packing team asks the status board for everything not yet sent, and gets both cards straight away, without reading every board.
  4. Ana hands in another card and the packing team asks again right away. The runner hasn't copied it yet, so the answer misses it.
  5. A moment later the runner catches up, and the next question sees all three cards.
Eventually or strongly consistent readsStep 5 of 5
๐Ÿข Building 1main๐Ÿฌ Building 2๐Ÿฃ Building 3Main boardv1key ana, status PENDING: v10v2key ana, status SHIPPED: v2123Copy boardv1key ana, status PENDING: v10v2key ana, status SHIPPED: v2123Copy boardv1key ana, status PENDING: v10v2key ana, status SHIPPED: v2โœฆโœฆโœฆโœฆโœฆ123๐ŸชShop
  1. Board 1 hangs in three buildings, the main board and two twin copies. All three show version 1 of Ana's card.
  2. The shop updates the card. The main board and one copy have the new version, so the shop hears "got it". Building 3 hasn't caught up yet.
  3. The shop asks a quick question. It happens to reach building 3, which still shows the old version.
  4. This time the shop asks for a sure answer. It always comes from the main board, so it shows the new version, at twice the price.
  5. A moment later building 3 catches up, and every copy agrees again.
Conditional writes for optimistic lockingStep 4 of 4
Ana's card, each versionv3key version 3, status PENDING: v30v4key version 4, status SHIPPED: v41v5key version 5, status SHIPPED, giftNote: v5โœฆโœฆโœฆโœฆโœฆ23๐Ÿ‘ฉShop worker Lu๐Ÿ‘จShop worker Bo
  1. Two shop workers, Lu and Bo, look at Ana's card at the same moment. Both see "version 3" at the top.
  2. Lu hands in a new card with a note, swap it only if it still says version 3. It does, so the swap goes through.
  3. Bo hands in a change with the same note. The card now says version 4, so it's refused, and Lu's change is safe.
  4. Bo reads the card again, redoes the change on top of version 4 and hands it in. This time it fits.

๐Ÿงฉ Key questions

The shop wants every card that mentions a red scarf, and the names on the cards don't help. What happens?
Someone reads along every board, card by card, and you pay for all of them. Only the name tells the steward which board to look at. For a question you ask often, keep an extra board sorted the way you need.
During a sale, every card is written under the name "Sale". The shop booked plenty of cards per second, yet the steward says to come back later. Why?
One name always goes to one board, and each board can only take so many cards a second. Spreading the cards over names like "Sale 1", "Sale 2" and "Sale 3" shares the work between boards.
The shop updates Ana's card, hears "got it", then immediately asks a quick question and sees the old version. Is something broken?
No: the quick answer can come from a copy that's a moment behind; ask for a sure answer if it matters. Copies catch up within moments. A sure answer comes from the main board and costs twice as much. The status board can lag too.
Two shop workers both read version 3 of a card and both hand in changes marked "only if it still says version 3". What happens?
The first goes through; the second is refused, reads the card again and redoes its change. The check and the swap happen together, so no change is silently lost.