We already became familiar with actors in Chapter 10, Background Tasks and Thread Pools in Microservices, but let's talk about using actors for microservices.
An actor is a model for doing concurrent computations. We should know the following models:
- Threads: In this model, every task works in a separate thread
- Fibers or green threads: In this model, every task has work scheduled by a special runtime
- Asynchronous code: In this model, every task is run by a reactor (actually, this is similar to fibers)
Actors combine all these approaches into an elegant one. To do any part of the work, you can implement actors that perform their own part of the work, and interact with other actors through messages to inform each other on the overall progress. Every actor has a mailbox for incoming messages and can send messages to other actors using this address.