Simplified
Simplified

L1.1Many servers, one database

YOU

Many servers, one database

BenCyAdaCourses120 XPSimplified's serverSimplified's server120databaseusersidnamexp1Ada1202Ben40?
Ada opens lesson 3Cy opens CoursesBen answers a questionDee answers a questionSimplified's serverSimplified's serverbuilding itchecking answerssaving themserver Aserver Aserver Bserver Bhalf the workhalf the work?
server Aserver Aserver Bserver Bserver A's databaseusersidnamexp1Ada120read-onlyserver A's databaseusersidnamexp1Ada120server B's databaseusersidnamexp1Ada120read-onlyserver B's databaseusersidnamexp1Ada120Ada: lesson 3Ada opens Courses
database serverPostgresusersidnamexp1Ada130server Aserver Aserver Bserver B130130Supabase's serveryour Postgres

Databases · Lesson 1.1

A Second Copy

Many servers, one database

Simplified
0:00 / 1:53

When Ada opens Courses on Simplified, Simplified's server builds that page for her.

A server is a computer that runs an app for everyone who uses it.

But the server doesn't keep Ada's progress itself: it asks its database for it.

A database is a program whose whole job is to keep data on disk, and answer questions about it.

Simplified's database is Postgres, which keeps every learner's row, like Ada's 120 XP.

So the server asks Postgres for Ada's row, and puts her 120 XP on the page.

BenCyAdaCourses120 XPSimplified's serverSimplified's server120Postgresusersidnamexp1Ada1202Ben40

But what happens when thousands of learners open lessons at the same moment?

Every page takes the server some work: building it, checking answers, saving them.

One server can only handle so many requests a second, so the rest would wait.

So Simplified runs two servers side by side: server A and server B.

Each learner's request goes to one of them, so each does about half the work.

Ada opens lesson 3Cy opens CoursesBen answers a questionDee answers a questionSimplified's serverSimplified's serverbuilding itchecking answerssaving themserver Aserver Aserver Bserver Bhalf the workhalf the work

So does each server get its own database too?

server Aserver Aserver Bserver Bserver A's databaseusersidnamexp1Ada130read-onlyserver A's databaseusersidnamexp1Ada130server B's databaseusersidnamexp1Ada120read-onlyserver B's databaseusersidnamexp1Ada120

Say server A had its own database, and server B another.

Ada finishes lesson 3, and server A saves her 130 XP in its database.

Then she opens Courses, and server B handles it, from its own database.

There, Ada still has 120 XP, so her XP depends on which server she reaches.

database serverPostgresusersidnamexp1Ada130server Aserver Aserver Bserver B130130Supabase's serveryour Postgres

So instead, server A and server B both ask the same database, Postgres.

Postgres runs on a computer of its own, so both servers can reach it.

This computer is called the database server.

The database server is the computer that runs the database, for every server that asks it.

It's like your Supabase project: Supabase started your Postgres on one of its servers.

So Ada sees 130 XP, whichever server she reaches.

So however many servers Simplified runs, they all share one database server.

Example: Many servers, one database

Simplified runs server A and server B, and both ask one database server. Ada has 120 XP. She finishes lesson 3, worth 10 XP, on her laptop, and server A saves her new XP. Then she opens Courses on her phone, and server B handles that request.

What XP does server B load for Ada?

Explanation

First, server A saved Ada's 130 XP to the one database server.

Then, server B asks that same database server, so it reads the 130 that server A saved.

Therefore, server B loads 130 XP.

Question 1

Simplified's server A and server B both ask Postgres for learners' rows. Postgres runs on a computer of its own.

What is that computer called?

What if the database server dies?

server Aserver Aserver Bserver Bdatabase serverusersidnamexp1Ada1202Ben40read-onlydatabase serverusersidnamexp1Ada1202Ben40save Ada's 130 XPload Ben's progresssingle point of failure?
WhatsApp's serverWhatsApp's serverWhatsApp's serverWhatsApp's serverdatabase servermessagesidfrom7Benread-onlydatabase servermessagesidfrom7Benyour friend's messageyour chats?
server Aserver Aserver Bserver Bdatabase serverusersidnamexp1Ada1202Ben40read-onlydatabase serverusersidnamexp1Ada1202Ben40?
server Aserver Aserver Bserver Bserver Cdatabase serverusersidnamexp1Ada1202Ben40read-onlydatabase serverusersidnamexp1Ada1202Ben40

Databases · Lesson 1.2

A Second Copy

What if the database server dies?

Simplified
0:00 / 1:33

So server A and server B share the work, and both ask one database server.

And every row Simplified keeps is on that one machine's disk.

But what happens to Simplified if that one database server dies?

server Aserver Aserver Bserver Bdatabase serverusersidnamexp1Ada1202Ben40read-onlydatabase serverusersidnamexp1Ada1202Ben40save Ada's 130 XPload Ben's progresssingle point of failure

Say the database server dies, and doesn't come back.

This isn't a restart: the machine is gone, and its disk with it.

Server A and server B still run, but every request that needs the database fails.

Ada finishes lesson 3, and server A can't save her 130 XP.

Ben opens Courses, and server B can't load his progress.

A part like this database server is called a single point of failure.

A single point of failure is one part whose loss stops everything.

Now what might happen to WhatsApp, if it had just one database server?

WhatsApp's serverWhatsApp's serverWhatsApp's serverWhatsApp's serverdatabase servermessagesidfrom7Benread-onlydatabase servermessagesidfrom7Ben

Say WhatsApp kept every message on one database server.

Say it dies, and doesn't come back.

Your friend sends you a message, and WhatsApp's server can't save it.

You open your chats, and WhatsApp's server can't load them.

WhatsApp's servers still run, but no one can send or read a single message.

So why didn't running two servers, A and B, remove it?

server Aserver Aserver Bserver Bdatabase serverusersidnamexp1Ada1202Ben40read-onlydatabase serverusersidnamexp1Ada1202Ben40

If server A dies, server B is still running, and still reaches the database.

So losing server A doesn't stop everything.

But both servers send every query to the same database server.

So when that one machine dies, both of them fail together.

More servers like A and B don't help while they all need one database server.

Example: What if the database server dies?

Say Simplified adds a third server, C, so servers A, B and C share the work. All three send every query to one database server.

Which machine is a single point of failure?

Explanation

First, if server A, B or C dies, the other two still run, and still reach the database, so that loss doesn't stop everything.

Then, if the database server dies, every request that needs the database fails, on all three servers.

Therefore, the database server is the single point of failure.

Question 1

Say Duolingo runs four app servers side by side, to share the work, and all four send every query to one database server. For a rush of new learners, it adds a fifth app server, which sends its queries to the same database server. A single point of failure is one part whose loss stops everything.

How many single points of failure does Duolingo have now?

single points of failure

Question 2

Simplified runs server A and server B side by side, and both send every query to one database server. Say the database server dies, and doesn't come back, while server A and server B keep running. Dee answers a question in a lesson, and server A sends the database the write that saves her answer.

What happens to that write?

Question 3

Simplified runs server A and server B side by side, and both send every query to one database server. Say server A dies, and doesn't come back, while server B and the database server keep running. Ada has 120 XP. She finishes lesson 3, worth 10 XP, and server B handles it.

What happens?

Question 4

Simplified runs server A and server B side by side, and both send every query to one database server. Say the database server dies, and doesn't come back.

Why does every request that needs the database fail, even though server A and server B are still running?

Question 5

Simplified's server A and server B both send every query to one database server, so if it dies, everything stops.

One part whose loss stops everything is called a what?

Question 6

You made a free Supabase project, and Supabase started your Postgres database just for you, on one of its servers. Say your app sends every query to that one database server, and that machine dies, and doesn't come back.

What happens to your app's queries?

Rows that outlive their machine

server Aserver Aserver Bserver Bserver Cdatabase serverusersidnamexp1Ada1302Ben40read-onlydatabase serverusersidnamexp1Ada1302Ben40database serverusersidnamexp1Ada1302Ben40read-onlydatabase serverusersidnamexp1Ada1302Ben40every change??
Instagram's serverInstagram's serverdatabase serverphotosidposted by9youphotosidposted by9youread-onlydatabase serverphotosidposted by9youreplicaphotosidposted by9youphotosidposted by9youread-onlyreplicaphotosidposted by9you?

Databases · Lesson 1.3

A Second Copy

Rows that outlive their machine

Simplified
0:00 / 1:38

So when Simplified's one database server dies, every request that needs the database fails.

Because every row Simplified keeps is on that one machine's disk.

And if it never comes back, those rows are gone with it.

So how can Simplified keep its rows, even when that machine dies?

Not with a third server like A and B, which keep no rows, but a second database server.

The second one holds a copy of every row the first one has.

This second database server is called a replica.

A replica is a second database server that holds a copy of every row, kept up to date.

server Aserver Aserver Bserver Bdatabase serverusersidnamexp1Ada1302Ben40read-onlydatabase serverusersidnamexp1Ada1302Ben40replicausersidnamexp1Ada1302Ben40read-onlyreplicausersidnamexp1Ada1302Ben40every change

So what happens now, if the first database server dies?

server Aserver Aserver Bserver Bdatabase serverusersidnamexp1Ada1302Ben40read-onlydatabase serverusersidnamexp1Ada1302Ben40replicausersidnamexp1Ada1302Ben40read-onlyreplicausersidnamexp1Ada1302Ben40

Say it dies, just after Ada finished lesson 3 with 130 XP.

Server A and server B can't reach the first database server any more.

But the replica has a copy of Ada's row, with her 130 XP.

And of every other row, because the replica is kept up to date.

We will explore how the replica stays up to date in the next lesson.

For now, just know it gets every change the first one makes.

And how server A and server B switch to it comes in a later lesson.

Now how might Instagram keep your photos, when one of its machines dies?

Instagram's serverInstagram's serverdatabase serverphotosidposted by9youread-onlydatabase serverphotosidposted by9youreplicaphotosidposted by9youread-onlyreplicaphotosidposted by9you

Say Instagram keeps your photos on a database server, with a replica of it.

You post a photo, and the replica gets a copy of it too.

Then say the first database server dies, and doesn't come back.

Your photo is still on the replica, so it isn't lost.

A replica keeps a copy of every row, so the rows outlive the machine that first wrote them.

Example: Rows that outlive their machine

Simplified's first database server and its replica both have Dee at 300 XP. Dee finishes a lesson worth 20 XP, and the replica gets the change too, so both now have 320. Then the first database server dies, and doesn't come back.

What XP does the replica hold for Dee?

Explanation

First, the replica holds a copy of every row, kept up to date, so it got Dee's 320.

Then, the first machine dying doesn't touch the replica's copy.

Therefore, the replica holds 320 XP for Dee.

Question 1

Simplified runs a second database server beside its first one.

What makes the second one a replica?

Question 2

Say Simplified kept all 2,000,000 learners' rows on one database server, with no replica. That database server dies, and doesn't come back.

How many of those learners' rows can Simplified still read?

rows

Question 3

Simplified wants every learner's row to survive its database server dying, and never coming back.

Which of these does that?

Question 4

Say Simplified copied every row onto a second database server on Monday, and never again. Ada had 120 XP on Monday. On Tuesday she finishes lesson 3, worth 10 XP, and the first database server saves her 130. On Wednesday, the first database server dies.

How much XP does the Monday copy hold for Ada?

XP

Question 5

Say Spotify keeps your playlists on a database server, with a replica of it. You add a song to a playlist, and the replica gets the change too. Then the first database server dies, and doesn't come back.

Where is your playlist with the new song now?

Question 6

Simplified runs one database server and one replica, and each holds all 2,000,000 learners' rows, kept up to date. The first database server dies, and doesn't come back.

How many learners' rows can Simplified still find?

rows
Assistant

Highlight lesson text and click Ask AI, or type a question below.