Notes

Part 8 of 10

Distributed versus single-node systems

A distributed system is several machines working together over a network. Each process taking part is a node.

Reasons to go distributed:

  • Built-in distribution: when many users each have their own device, those devices must talk over a network.
  • Calls between cloud services: data stored in one service and processed in another must cross the network. So cloud native systems, and apps built from microservices, are distributed by nature.
  • Fault tolerance and high availability: spare machines take over when one machine, network link, or whole datacenter fails.
  • Scalability: the data or the work grows too big for one machine, so the load is spread out.
  • Latency: servers in several regions answer users from nearby.
  • Elasticity: add machines in busy hours, remove them in quiet ones, and pay only for what you use. A single machine must be sized for the peak.
  • Special hardware: different parts can run on machines that suit them, like storage nodes packed with disks, analytics nodes heavy on processors and RAM with no disks at all, or GPU nodes for machine learning.
  • Legal compliance: some countries require data about their residents to stay inside the country. The scope varies; sometimes it covers only health or financial data. A service with users in many countries must then spread its data across them.
  • Sustainability: run flexible jobs at times and places where renewable power is plentiful and the power grid is not strained. This cuts carbon and often costs less.

These reasons apply both to services you write yourself and to ready-made software like databases.

Problems with distributed systems

Guess first

A client asks a server to book a seat, and gets no reply before its timeout. Did the server book the seat?

A client asks a server to book a seat, and gets no reply before its timeout. Did the server book the seat?

Try it

Did it work?

The client asks a server to book seat 12A.

What happens on the way

The client sees

Nothing sent yet

What really happened

-

Seat 12A was booked 0 times.

Real clients wait a set time for a reply. When it runs out, they only know that no answer came back.

  • Any network call can fail. The network can drop, the other service can be overloaded or crashed, or the call can time out with no answer. After a timeout you do not know whether the other side got the request, so retrying blindly may not be safe.
  • A call to another service, even inside a fast datacenter, is far slower than a function call in the same process.
  • With large amounts of data, it can be faster to send the code to the machine holding the data than to move the data to the code.
  • More nodes are not always faster. A simple single-threaded program on one machine can beat a cluster with over a hundred cores.
  • Finding the cause of a problem is hard: which part of the system is slow? Observability means collecting data about how the system runs and being able to query it, both as high-level metrics and as single events.
  • Tracing tools follow a request as it hops between services, noting each call, what it was for, and its duration.
  • If each service owns its own database, keeping data consistent across services becomes the app's job. Distributed transactions can help, but they are rarely used with microservices, because they tie services together and many databases do not support them.
  • So, if the work fits, one node usually wins on both simplicity and cost. Hardware has grown bigger, faster, and more reliable, and with single-node databases like SQLite or DuckDB, many workloads fit on one node.