|
|
|
|
|
by mungobungo
1314 days ago
|
|
Well, let’s assume we are talking about a webshop. Every user is represented as an actor, a cart might be a state.
So cart as a state should be stored somewhere else, let’s say redis.
And every single read/write operation would be a network hop. What are the benefits of using actor model then ? As for state handover between pods - what are the keywords to look for ? |
|
A typical Phoenix app spawns one process for every HTTP request, websocket channel, or DB connection, for example. All these things have a lifetime shorter or equal to the pod's.
The VM gives guarantees and tools to ensure one of these process crashing will not affect the others, unless you want it to. For instance, if a request crashes, its memory will be reclaimed, open files will be closed, DB connections will be re-opened, the exit reason will be logged, error metrics incremented, etc. This is possible with no defensive programming like try/catch and so on, because the processes are isolated. For example they don't share memory, so it's always safe to deallocate something if its owner process died.
This gives a two-layer safety net that allows for very reliable apps, where the VM protects you against bugs in your own code, and Kubernetes protects you against bugs in Erlang, or really catastrophic failures. There's a good blog post on this: http://blog.plataformatec.com.br/2019/10/kubernetes-and-the-...