seegongsik
Data

How does distributed data work

What happens as data keeps piling up? Even the biggest warehouse fills up someday. So you add more warehouses and split the load among them, and in case one collapses, you keep copies of the same goods in another warehouse so nothing is lost. Data works the same way. When one computer cannot cope, the data is split across several, and copies are kept on several machines in case of failure.

01

One machine stops being enough

Up to the last lesson, we saw how to store data, find it, change it safely, and handle it fast and small. But data never stops piling up: more users, more records, and photos and videos on top of that.
There is a limit to how much one computer can hold. The size of its disk is fixed, and so is the number of requests one machine can handle at once. Below, let's keep adding data to a single machine.

one machine's capacity
Tap to add more data
0 / 8

Keep tapping add data. Once one machine's capacity is exceeded, it cannot hold any more.

The machine is full. Even if you want to add more, there is no room. One option is to switch to a bigger computer; this is called scaling up, or vertical scaling. But bigger computers get steeply more expensive, and however big you go, it eventually fills up again.
So you take another route: instead of making one machine bigger, you add more machines. This is called scaling out, or horizontal scaling. Then how do you split data across several machines?

02

Split it across several machines

You break the data into pieces and spread them across several machines. Instead of one machine shouldering everything, each machine takes on only part of it. Spreading data out like this is called distribution, and cutting the data itself into pieces is called sharding.
There are several ways to decide the split. You can split by range, putting data whose names begin with A to M on machine 1 and N to Z on machine 2, or you can use a hash, as we saw earlier, to turn each key into a number and spread the data evenly according to that value. Splitting by range can pile data up in certain ranges, so a hash is often used when you want an even spread.

pieces to split
A
B
C
D
E
F
machine 1
machine 2
machine 3
Tap to split pieces across the machines

Tap the pieces one by one to split them across several machines. Each machine ends up holding only part of the whole.

The pieces are spread across three machines. The load one machine carried has lightened, and when the data grows further, you just add another computer and hand it the new pieces. Because you can keep growing this way, even very large data can be held.
To find a piece of data, you first need to know which machine it is on. Since the rule for splitting is known, the key alone tells you which machine to go to. But a new worry appears. What if the one machine in charge of a piece suddenly breaks down?

03

Keep copies of the same data on several machines

Splitting the data creates a weak point. If the computer in charge of a piece fails, that piece disappears entirely. And the more computers there are, the more often one of them somewhere breaks down.
So copies of the same data are kept on several machines. If one machine stops, another that holds a copy takes over, so no data is lost. Keeping the same data on several machines like this is called replication. With copies in place, read requests can also be shared among several machines.

Copy first, then turn one machine off

Make the copies first, then turn one machine off. Even with one machine off, another holding a copy stays up, so the data survives.

With one machine off, the data was unharmed, thanks to the copies. It is important to keep two things apart here: distribution splits the data and divides it among different machines, while replication keeps the same data on several machines. Real systems usually use both together, keeping copies of each piece.
Replication has a cost too. Every time data changes, all the copies have to be brought into line, and since machines take time to communicate, the copies may briefly hold different values. When the network breaks, there comes a moment when you must choose between answering right away, even with an old value, and waiting until the copies agree.

04

Looser containers: NoSQL

When data is enormous and must go in and out very quickly, a strict table can become a burden. Every row has to have the same columns, and keeping joins and transactions working across many machines is expensive.
So stores that loosen those rules are used instead. Rather than a table, they hang one value on one key, so data goes in and comes out straight away. They are like the hash table we saw earlier grown across many machines, so the key alone also settles which machine holds the data. Stores like these are grouped together under the name NoSQL.

strict table
-
loose key-value (NoSQL)
-
Tap a test to compare the two containers

Tap a test to compare the strict table with the loose key-value container. The loose container is the one with a free shape that suits huge, fast workloads.

Having fewer rules makes the loose container freer and faster. Rows can have different columns, and as long as there is a key, a value goes in and comes out at once. In exchange, some conveniences, such as joins between tables and strict transactions, are partly given up.
So you choose what to gain and what to give up to fit the job: a strict table where accuracy comes first, as in a ledger where money changes hands, and a loose container where huge numbers of records must be piled up fast. It is common for a single service to use both.

05

Wrapping up the data area

We have come a long way. Starting with data structures that hold values, we saw the database that gathers tables, and learned to find things fast in a big table with hashes, trees, and indexes. We asked questions with SQL and linked tables with joins, trimmed duplication with normalization, and changed data safely with transactions.
We also saw how caching and compression make data faster and smaller. And today we reached the point of splitting data and keeping copies when one machine is not enough.

Tap the big threads of the data area in order to close it

Tap the big threads of the data area in order to close it. (data structures as containers → the database that gathers tables → finding fast → asking and linking → tidying and changing safely → fast and small → splitting and replicating)

Today's lesson comes down to this. When data is too much for one machine, it is cut into pieces and split across several (distribution), and copies of the same data are kept on several machines in case of failure (replication). Splitting and copying are different jobs, and in practice the two are used together.
For huge and fast workloads, stores that loosen the rules of the table, known as NoSQL, are sometimes used. The key is choosing what to gain and what to give up.

Now the big picture of handling data comes into view at a glance. From a single small container, we have come all the way to a large operation that splits and copies data across many machines. This craft of storing information safely, finding it fast, and growing it large becomes the foundation for the next area.
The next area is artificial intelligence, where machines find rules for themselves in places where a lot of data gathers. Its first lesson begins with what it means for a machine to learn.

In one lineWhen data grows too big for one computer to cope with, it is cut into pieces and split across several machines. This is called distribution, and cutting the data into pieces is called sharding; a range or a hash decides which machine each piece goes to. Since each machine takes on only part of the whole, adding computers lets you hold ever larger data. So that no data is lost when one machine fails, copies of the same data are kept on several machines; this is replication. Distribution splits and replication copies, so they are different jobs, and since bringing copies into line takes time, values can briefly disagree. For huge and fast workloads, stores that loosen the rules of the table are called NoSQL, and a key-value store is like a hash table grown across many machines.
← Data
Was this helpful? Support seegongsik