← All transcripts

How Key value Stores Work (Redis, DynamoDB, Memcached)? Transcript, AI Summary & Key Points

ByteByteGo · Aug 20, 2025 · Science & Technology · 06:00 · EN-US

Answer

Key-value stores distribute key-value pairs across servers using hashing, replication, consistency strategies, conflict resolution, and failure-detection protocols.

AI Summary

A key-value store is a database organized like a giant dictionary, with keys mapped to values. At large scale, data must be distributed across thousands of servers. Consistent hashing limits data movement when servers are added, replication keeps data available when servers fail, and eventual consistency addresses conflicting copies. Vector clocks can track conflicting versions, while gossip protocols help servers detect failures without requiring every server to communicate directly with every other server.

Key Points

  • A key-value store maps a key, such as user 1 2 3 4 5 cart, to a value such as the items in a shopping cart.
  • Large systems can require terabytes of data per major region, billions of key-value pairs, and millions of accesses per second.
  • Hashing a key and using modulo across the number of servers causes nearly every key to move when a server is added.
  • Consistent hashing places keys and servers on a circle and assigns each key to the first server encountered while moving clockwise.
  • Adding a server at position 500 causes keys hashing to positions 101 through 500 to move to that server while other keys remain where they were.
  • Replicating data on multiple clockwise servers allows the data to remain available when one server fails.
  • Distributed systems must choose trade-offs among consistency, availability, and network reliability; the transcript states that perfect versions of all three cannot be achieved at the same time.
  • Consistency may require refusing requests when servers cannot communicate, while availability may involve serving stale data.

🔒 4 more in the full analysis

Links mentioned

🔒 Full analysis locked

Unlock more videos and the full analysis

Buy credits to process more videos. Each run includes the full analysis, not just the summary — and you get access to the locked analysis across the library.

Inquire for details →

From this video

1 product

ByteByteGo

Transcript

Searchable transcript of How Key value Stores Work (Redis, DynamoDB, Memcached)? — ByteByteGo (06:00). Search for a phrase, then click its timestamp to jump straight to that moment in the video.

Captions sourced from the original video on YouTube, published by ByteByteGo. The video, its captions and all related intellectual property remain the property of their respective owners; AINotes claims no ownership. Provided for research, accessibility and search — see the Transcript Notice and Copyright Policy.

00:00 Today we're looking at key value stores, a type of database that keeps track of everything from your shopping cart to your chat messages. And what starts as a simple idea quickly becomes a hot problem in software engineering. So what is a key value store? Think of it as a giant dictionary. You have a key, maybe user 1 2 3 4 5 cart and a value. All the items in that user's shopping cart.

00:24 You can put data in, you can get data out. Here's the thing, though. Amazon stores everything. We're talking about terabytes of data per major region with billions of key value pairs that need to be accessed millions of times per second. No single computer can handle that load. So, you need to spread it across thousands of servers. But now you have a problem.

00:47 When someone asks for user 1 2 3 4 5 cart, how do you know which server has it? Your first instinct might be just hash the key and use modulo. Hash the key, divide by the number of servers, use the remainders to pick a server. Simple math. But here's where it gets tricky. What happens when you need to add a new server? Suddenly, you're dividing by a different number and almost every key maps to a different server.

01:14 You would have to move nearly all your data just to add one machine. This is where consistent hashing comes in, and it's pretty clever. Instead of mapping keys directly to servers, imagine both keys and servers living on a giant circle. Think of a clock face, but instead of 12 hours, you have millions of positions. You place your servers at random spots around this circle.

01:36 Maybe server A is at position 100. Server B is at position 1,000. Server C is at position 5,000. Now, when you want to store user 1 2 3 4 5 cart, you hash that key to get a position on that circle. Let's say position 750. You site at that spot and walk clockwise until you hit the first server. In this case, that would be server B at position a th00and.

02:00 The magic happens when you add a new server. Say you place server D at position 500. Now keys that hash to position 101 through 500 go to server D instead of server B. But everything else stay exactly where it was. You only move a fraction of your data. But wait, what happens when server B crashes? Now all those keys has nowhere to go. This is where you need copies.

02:24 Instead of storing each piece of data on just one server, you store it on multiple servers. One way to do this is to keep using that circle. When user 1 2 3 4 5 card hashes to position 750, you don't just store it on server B. You also store copies on the next two servers clockwise. Maybe server C and server A. Now, if server B goes down, you still have the data.

02:49 Great. Now, your data is safe, but you've created a much bigger headache. Let's say two people are shopping for the same family account. They both add items to the cart at the exact same time, but their requests hit different servers. Now, you have two different versions of the same shopping cart. Which one is correct? This brings us to one of the fundamental concepts of distributed systems.

03:11 You cannot have perfect consistency, perfect availability, and perfect network reliability all at the same time. You have to pick two. If you choose consistency, making sure everyone always sees the latest data. You might have to refuse requests when server can't communicate. Banks do this because showing the wrong account balance is unacceptable. If you choose availability, keeping the system running no matter what, you might occasionally serve stale data.

03:39 Most web apps do this because it's better to show an old shopping cart than no shopping cart at all. The solution most big systems use is called eventual consistency. The idea is simple. Given enough time, all the copies will match up. But right now, this instance, they might be a little different. This creates a new challenge. How do you handle conflicting versions?

04:04 There are different approaches to this problem. One clever solution is called vector clocks. Think of it like a version number but smarter. Every time a piece of data gets modified, it gets tagged with information about which server did the modification and when. When you detected two conflicting versions, you have a few options. Sometimes you can automatically merge them like combining two shopping carts to include all the items.

04:27 Sometimes you have to ask the users to choose. Sometimes you just pick the most recent one and hope for the best. Next problem. In a system with thousands of servers, machines are failing constantly. How do you even know when a server is down? The naive approach is to have every server ping every other server. But with thousand servers, that's nearly a million connections.

04:50 It doesn't scale. One solution that works well is called a gossip protocol. Each server keeps a list of all the other servers and occasionally shares that list with a few random neighbors. If server X stops responding, the gossip spreads throughout the entire cluster. It's exactly like how rumor spreads in high school. Surprisingly effective, and you don't need everyone talking to everyone.

05:14 What started as remember this shopping cart turns into a master class in distributed systems engineering. And this is just the beginning. We haven't even touched storage engines, data center failures, or performance optimization across thousands of machines. The next time you add something to your cart and it just works, you'll know there's an intricate dance happening across data center around the world.

05:36 All to make sure your data is exactly where you expect it to be. Ready to ace your next technical interview? Join our community where we offer comprehensive courses on system design, coding, behavioral questions, machine learning, and object-oriented design. Learn more at byitebico.com.