7 Building a concurrent system

 

This chapter covers

  • Working with the mix project
  • Managing multiple to-do lists
  • Persisting data
  • Reasoning with processes

The concurrent examples you’ve seen so far have relied on a single server-process instance. But typical Elixir/Erlang systems are powered by a multitude of processes, many of which are stateful server processes. It’s not uncommon for a moderately complex system to run a few thousand processes, whereas larger systems may be powered by hundreds of thousands or even millions of processes. Remember that processes are cheap, so you can create them in abundance. And owing to message-passing concurrency, it’s still fairly easy to reason about highly concurrent systems. Therefore, it’s useful to run different tasks in separate processes. Such a highly concurrent approach can often improve the scalability and reliability of your systems.

In this chapter, you’ll see an example of a more involved system powered by many processes that cooperate to provide the full service. Your ultimate goal is to build a distributed HTTP server that can handle many end users who are simultaneously manipulating many to-do lists. You’ll do this throughout the remaining chapters and reach the final goal in chapter 12. In this chapter, you’ll develop an infrastructure for handling multiple to-do lists and persisting them to disk.

But first, let’s look at how you can manage more complex projects with the mix tool.

7.1 Working with the mix project

7.2 Managing multiple to-do lists

7.2.1 Implementing a cache

7.2.2 Writing tests

7.2.3 Analyzing process dependencies

7.3 Persisting data

7.3.1 Encoding and persisting

7.3.2 Using the database

7.3.3 Analyzing the system

7.3.4 Addressing the process bottleneck

7.3.5 Exercise: pooling and synchronizing

7.4 Reasoning with processes

Summary