Chapter 3. Scaling
Running redundant copies of a service is important for at least two reasons.
The first reason is to achieve high availability. Consider that processes, and entire machines, occasionally crash. If only a single instance of a producer is running and that instance crashes, then consumers are unable to function until the crashed producer has been relaunched. With two or more running producer instances, a single downed instance wonât necessarily prevent a consumer from functioning.
Another reason is that thereâs only so much throughput that a given Node.js instance can handle. For example, depending on the hardware, the most basic Node.js âHello Worldâ service might have a throughput of around 40,000 requests per second (r/s). Once an application begins serializing and deserializing payloads or doing other CPU-intensive work, that throughput is going to drop by orders of magnitude. Offloading work to additional processes helps prevent a single process from getting overwhelmed.
There are a few tools available for splitting up work. âThe Cluster Moduleâ looks at a built-in module that makes it easy to run redundant copies of application code on the same server. âReverse Proxies with HAProxyâ runs multiple redundant copies of a service using an external toolâallowing them to run on different machines. Finally, âSLA and Load Testingâ looks at how to understand the load that a service can handle by examining benchmarks, which can be used to determine ...
Get Distributed Systems with Node.js now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.