Skip to main content
CodeOath

Design: low-level, high-level and patterns · Chapter 2

Caching and database scaling

About this chapter

A cache spends a little fast storage to take load off whatever sits behind it, and a database that outgrows one machine has to give up some of the guarantees a single copy provides for free. This chapter follows a ticket-selling system through both problems: how a cache is filled and emptied, what happens when many requests miss at once, and how extra read copies and sharding spread a database.

Who it is for: Engineers preparing for system design rounds who know the basic parts of a web service and want to reason about speed and load with numbers.

You will be able to

  • Explain how a cache is filled, when its entries expire or are evicted, and why a burst of misses can swamp the database.
  • Say when moving static files to a content delivery network is the right first step.
  • Explain why keeping cached copies correct after the data changes is the hard part.
  • Describe what a leader with followers gives you and what it costs in freshness.
  • Describe how sharding splits data across machines and say what it makes harder.

The key idea: Speed and correctness pull against each other. Every extra copy of the data, in a cache or in a follower database, is quicker to read and may be out of date. The design question is how stale each copy is allowed to be, and who is told when the original changes.

In this chapter

  1. Caching
  2. Database scaling

Locked: needs a plan

You can read chapter 1 free. Chapter 2 is the next one.

What you can do now, free: re-read chapter 1 and try its problems.

What a plan gives you: all chapters of the track you pick and their checks. Professional, one role is ₹329 a month or ₹2,299 a year. It renews until you cancel, and you can cancel any time. Paid plans open at launch.

Why is this locked?

Chapter 1 of every track is free, so you can see how the track reads. The rest of a track and its checks come with a plan, or open as you pass each chapter's check.

The price is for one period, a month or a year. A plan renews until you cancel.

Back to the track