[erlang-questions] Using processes to implement business logic

Camille Troillard lists@REDACTED
Fri Jan 30 18:03:34 CET 2015

Hi Garret,

Thank you for taking the time to answer my email.

On 30 Jan 2015, at 15:45, Garrett Smith <g@REDACTED> wrote:

>> I am looking for opinions about using processes to encapsulate the state of business entities.
> By using the term "business entity" you've tipped your hand I'm afraid :)
> It's hard, and not productive in my experience, to map RDBMS and/or OO
> modeling concepts into Erlang. People do it, try it, etc. - but I just
> don't think it's a good fit.

Sorry if the term entity was confusing, I was not using it this way.
As I did not want to go into the discussion of Object Oriented Programming, I tried to find a less opinionated word for a “thing”, part of the domain model. You’ll noticed that I did not talk about mapping a RDBMS either, just persistence.


> A process is an independent thread of execution. So if you have any
> sort of independent activity in your app, you'll need processes. You
> in fact might not. If you're building a web app, processes and their
> lifecycle are handled by the web server - you'll just feed it
> functions. Where are the business entities here? Don't look for them.

I don’t see how the implementation of the business logic as to do with the external interface (web server).


>> Now another question... given this “actor” based approach, I am having difficulties to figure out a proper way of dealing with processes lifetime. How would you do this in practice? Manually, or implement simple garbage collection, reference counting, ...?
> Sticking with "user" as our business entity (sigh) what's its
> lifetime? Unless you are building a simulator where users come and go
> quickly, we're certainly not talking about representing a user with a
> process. For me it's very hard to even think of a "user" as existing
> at all in a typical businessy app. You have "user state" - and that
> will be initially created by some *activity* or trigger - e.g. some
> HTTP request from a web app (someone clicked "Create User" on a web
> form). Then some other event comes along - maybe a timed cron job -
> and it checks some state of a "user" and performs some work. Or
> someone requests a web page and you have to read user state. It's all
> activities here (processes) and logic (functions).

Again, I don’t understand why the web server would have anything to do with the of implementing a user as a process or a record. That does not rule out the possibility to modelling a user entity (or actor, or object, whatever you feel comfortable with) as a process.


More information about the erlang-questions mailing list