Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I do if I want to deploy Play Framework app to multiple servers?

If I would like to deploy my application using Play Framework 2.x to multiple servers, what are the things I need to care about?

  1. If I am using (built-in) sessions, will it be available to all the nodes since they are stored in browser side?

  2. How can I share variables application-wide except for storing them in the database?

like image 892
Ivor Zhou Avatar asked Nov 05 '25 02:11

Ivor Zhou


1 Answers

When putting a Play application in production to multiple server nodes, you should check following steps:

  • Ensure the application secret (that encrypts and signs the session cookie) IS THE SAME on every node, as you won't be able to which node will send the HTTP response.
  • Ensure that you did not use the built in cache system (ehcache) to store user specific information (as the cache is stored in server's memory).

That's all...

So to answer your other points:

  1. If you're using (built-in) sessions, information stored in the session cookie will be available to every server node (as it comes from the client). Just remember that a cookie is limited to 4kb in some old browsers (IE6), so be carefull about the quantity of information you put in the session.
  2. If you want to share other application wide variables:

    • if the information is user specific, you can also store them on the session, or in another cookie. For instance if you want to save current user's theme: response().setCookie("theme", "blue");. Then you can retrieve the stored information with Http.Request.current().cookies.get("theme"). You can have a deeper look into play sessions and cookie.

    • If you want to share other variables across multiple nodes, you'll have to use distributed cache solutions like memcached or, your database like you suggested.

If not already done, you should have a look into how to deploy play to production

like image 133
François Maturel Avatar answered Nov 07 '25 15:11

François Maturel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!