Thread Architecture vs Staged Event-Drive Architecture in real life:
Imagine you have a restaurant. Now, how it will work?
with “Thread Architecture”:
- A customer arrives
- Waiter(a) goes to him/her
- Waiter(a) takes him/her to one available table
- Waiter(a) takes the order
- Waiter(a) cooks the order
- Waiter(a) takes to order to the table
- Waiter(a) waits until the client finishes his/her meal to pay
- Waiter(a) walks the client out
In this case, the waiter is with the client during the whole process. If the server has 10 threads, can handle 10 connections concurrently.
with SEDA:
- A customer arrives
- Waiter(a) goes to him/her
- Waiter(a) takes him/her to one available table (and comes back for another client to come)
- Waiter(b) takes the order (lots of I/O, takes time)
- Cook cooks the order
- Waiter(c) takes to order to the table
- Waiter(d) waits until the client finishes his/her meal to pay
- Waiter(e) walks the client out
In this case, there are different kind of actors doing the activities. This helps to reuse actors in the activities that take less time and the outcome is more effective. Indeed, this is how a restaurant works (probably more instances of Waiter are the same person, but the cook definitely not).
This is an extreme example, and of course with threaded servers some async tasks can be done. This is only a theoretical example.