stateless play!

401 views
Skip to first unread message

bao sun

unread,
Jan 12, 2009, 5:31:42 AM1/12/09
to play-framework
Hi:

"5. Distribute an application to several JVM without configuring
anything

Since the server is totally stateless, you can just start the same
application on several server and load balance between applications at
HTTP level. No need to set up a complex application server cluster or
something alike." --quote from http://www.playframework.org/manual/contents/fivecoolthings

in real production world, many situations are stateful. user need to
signin and continue others. Apps are deployed on many app servers for
clustering. for example:

assumption:

same app deployed on app server-A and app server-B. with front server
C distribute request to A or B with round-robbin strategy.

1. user load page from server-A and signin.
2. server-A crashed . shutdown... restart...
3. user clicking some page
4. server-C distribute request to server-B
5. and then question is:
How to archive the stateless ? from user experience , it must look
seamless. Nothing happened in server backend.

has there some wiki pages , examples, "Howto write stateless code in
your apps" ,etc, to help us newbie?

looking for more Chinese buddy , go with Play!.





Guillaume Bort

unread,
Jan 12, 2009, 7:04:15 AM1/12/09
to play-fr...@googlegroups.com
Hi,

Since Play! store the session and flash data into a client cookie, the scenario you describe
will just work out of the box.

By stateless we mean that each request should contains enough information to be resolved without
the need of "magic" in memory data.

If you need to span some "large" data to span multiple requests, either store it in your datastore or even
in the cache (which can be easily distruted using memcached).

If you store some data into Play! server memory (like in a shared static Map) then you break the "stateless" contract.
It can be totally acceptable in some situations but you have to know that in this case you will not be able to distribute
naturally your application to several Play! server.

bao sun

unread,
Jan 12, 2009, 9:25:36 AM1/12/09
to play-framework
thanks.

you explain very clearly. I got it.

just save a uuid token of signin user to session. and save big object
or the other data to centre cache such as memcached.

that's scalable unlimitted.


On 1月12日, 下午8时04分, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> Hi,
>
> Since Play! store the session and flash data into a client cookie, the
> scenario you describe
> will just work out of the box.
>
> By stateless we mean that each request should contains enough information to
> be resolved without
> the need of "magic" in memory data.
>
> If you need to span some "large" data to span multiple requests, either
> store it in your datastore or even
> in the cache (which can be easily distruted using memcached).
>
> If you store some data into Play! server memory (like in a shared static
> Map) then you break the "stateless" contract.
> It can be totally acceptable in some situations but you have to know that in
> this case you will not be able to distribute
> naturally your application to several Play! server.
>

Guillaume Bort

unread,
Jan 12, 2009, 9:41:46 AM1/12/09
to play-fr...@googlegroups.com
Yes that's right.

Remember that the session cookie is signed (but not crypted !) with the Play! secret key.
So the session data is safe. It can't be modified from the client point of view. But all
Play! applications must share the same secret key ...
Reply all
Reply to author
Forward
0 new messages