Fist bumps Photo by on Unsplash

When designing your Elixir systems, think about the processes as people. Now think of these people in an office all working together to serve the customer. That is how you can build your software systems in Elixir. It’s natural and intuitive!

A Person’s State

A person’s mental “state” is like an Elixir process’ state.

  • You know what you are thinking about.
  • You don’t know what someone else is thinking. It is private to them.
  • You can ask that person what they are thinking.
  • That person can choose to reply and tell you what they are thinking.

Don't know current state

Send message and ask

Reply with answer

Elixir processes are very powerful. You might be tempted to think of a process as a “thread” in traditional “multi-threaded” programming but that’s wrong and will take you off course. “Threads” often share state and two people can’t do that. It’s unnatural and you end up resorting to things like mutexes to try and keep things from breaking.

Elixir’s processes provide a better way! And they are easier to think about too!

Your Software System is Like an Office

Your system is like an office. Let’s say the front door of your business is a website and a request just came in. Who services that request? Are multiple people involved in responding to that request?

If you have a Ruby on Rails or PHP system, then your business probably looks like a sole-proprietorship. A single-person operation. An individual request gets handled by a single process (or person). The business will do nothing else until that one request is dealt with.

Single person office

We get around this limitation by cloning the whole business and hiding that behind a facade to make it look like one building. In tech terms, we run multiple instances of the whole system behind load balancers but each instance of the system can only handle one request at a time.

Single person office

Elixir and Phoenix Scale Your Business!

When you build you business with Elixir and Phoenix, Phoenix takes care of hiring a new temp-worker for every request. That temp-worker handles the request and response. So, by just using Elixir and Phoenix, your system can handle more load with fewer resources and responds to each request faster.

Temp Worker per Request

That’s awesome! Your business serves more customers and adds employees on-demand and you don’t have to even think about it! You win!

Now, do you think it could get even better? Remember:

  • processes are like people
  • your system is like an office

Think of your system like an office. When you want to grow your business beyond the sole-proprietor model, how do you do that?

You hire people! You assign people roles or positions and have them work together to get more done! In fact, some of those people would be very specialized like the sales-gal and the finance-guy.

In tech terms, I create (hire) processes (people) and they send messages to each other to coordinate and now more people are working at the same time! This is how the real world works. This is how you work with other people. You understand this instinctively. The novelty is realizing that you can have a software system that works the same way.

Concurrent Workers

Now that is a real business!

The sole-proprietor model is a bottle-neck. A small business will remain small and unable to service more customers until they figure out how to scale and hire more people. Don’t make that mistake with your software systems! Elixir has the power to help you build a smarter business. That means you have a smarter system.

You Can Do This! How?

Elixir can do this. You can do this with Elixir! What do you do?

  • Think of your system like an office
  • Think of processes as the people in the office
  • How would you solve the problem with real people?
  • Hire more people!

Use more processes! Concurrency for the win!

Want to Move Faster?

Contact me to help your team and project get to that point faster!

Want More Detail?

Want to go deeper and get a better understanding? I presented on this topic and more at an Elixir meetup. We make process and concurrency real!