๐ 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.
- 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.
- The shop hands in Ana's first card. The steward reads the name, applies the fixed rule and pins it on board 1.
- Ben's card has a different name, so the same rule sends it to a different board.
- Ana orders again. Same name, so same board, and the card hangs right after her first one because its date is later.
- Cat's card mentions gift wrap and the others don't. That's fine; only the name and date have to be there.
- The boards already hold cards. Ana's three cards hang together on board 1, in date order.
- 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.
- 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.
- 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.
- On a normal day, cards carry lots of different names, so all three boards share the work.
- A big sale starts, and the shop writes every sale card under one name, "Sale". They all go to board 1.
- 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.
- 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.
- The shop hands in two new cards. They're pinned in the Orders hall as usual, by name.
- A runner copies a summary of each card onto the status board, arranged by status instead of name.
- The packing team asks the status board for everything not yet sent, and gets both cards straight away, without reading every board.
- 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.
- A moment later the runner catches up, and the next question sees all three cards.
- Board 1 hangs in three buildings, the main board and two twin copies. All three show version 1 of Ana's card.
- 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.
- The shop asks a quick question. It happens to reach building 3, which still shows the old version.
- 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.
- A moment later building 3 catches up, and every copy agrees again.
- Two shop workers, Lu and Bo, look at Ana's card at the same moment. Both see "version 3" at the top.
- 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.
- 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.
- 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.