[erlang-questions] Erlang processes and state management design

Ben Munat <>
Wed Oct 24 19:36:08 CEST 2007

Alexander Lamb wrote:
> Hello again,
> So, I am gradually understanding the design philosophy of an Erlang 
> application.
> On the one hand, functionnal programming is about having no state. 
> However, in the situation of a Web application, you obviously need to 
> keep some state otherwise you are back to PhP style (in the sense you 
> are recalculating everything at each request).

"Back to PHP style"? That's not PHP style... that is called "shared nothing" and 
is used in web apps in a lot of languages and frameworks. From my experience, 
reconstituting state on each request is highly recommended... it's the norm. I 
always keep session data in the database as well.

You should check out erlyweb... it offers a database layer that simplifies 
access to data in the function handling a request. Not sure how it handles 
sessions... that's probably a feature of yaws though.

Yariv? You lurking out there? Care to promote your framework here?


> I went back to Joe's book and read again the chapter on processes. And, 
> as someone suggested earlier, I realized the state of an Erlang program 
> can actually be kept in a process. So when designing an application, you 
> indeed model the processes, then the state of the processes, then the 
> messages.
> So for example, if I create a process for each user who logs in to a 
> program. Upon creation of the process I could fetch all the features and 
> worklists the user has, then keep them in his process until he logs out 
> (or after a given long timeout).
> I can do that for every task which needs to keep a state between requests.
> Therefore, I have a question: where is it usuall or reasonnable to keep 
> the state of a process?
> 1) in the parameters of the function we spawn
> 2) in the process dictionnary
> 3) in an ETS structure
> 4) in a in-memory mnesia structure
> I suppose it really depends on the amount of data and how it will be 
> modified (and if we want to keep persistent some session data after the 
> process is killed).
> Tell me if I am wrong, but the first two solutions will put data on the 
> process stack and will be destroyed when the process is killed. The two 
> other solutions will have to be cleaned out when the process is killed.
> Are there some guidelines?
> For a user process, I might have 30 or 40 features in a list, some 
> values about his account, etc...
> For a process managing (for example) browsing patients in a list, I will 
> have the list of patients with the visits for the currently selected 
> patient, etc...
> Thanks for any hints!
> Alex
> --
> Alexander Lamb
> Founding Associate
> 4 ch. de la Tour de Champel
> 1206 Geneva
> Switzerland
> Tel:  022 347 77 37
> Fax: 022 347 77 38
> http://www.rodanotech.ch
> ------------------------------------------------------------------------
> _______________________________________________
> erlang-questions mailing list
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list