Load balancing with sticky sessions and zero downtime…?

661 views
Skip to first unread message

Viktor Hedefalk

unread,
Dec 10, 2015, 5:06:03 AM12/10/15
to Lift
Hi,

I know this isn't really lift related, but I have had such great success asking for this kind of advice here before :)

I have used nginx and jetty to deploy my lift webapps almost exclusively. However, I now face the problem that I REALLY need zero downtime rolling releases for a project

So I'm trying to understand how to do this with nginx. Seems the load balancing strategies of nginx without premium just doesn't cut it. I mean, I have to look at cookies (JSESSIONID) and be sticky on that, but have a way to empty one server of sessions until it's gone. Seems to only have basic strategies like IP hash which just wont work.

I know Tomcat has had a simple version of this internally that I used at one point: http://java-monitor.com/forum/showthread.php?t=1288 but I would rather stick with jetty.

Should I just give up and use something more enterprizy? glassfish?

What do you guys use?
Cheers,
Viktor

Vasya Novikov

unread,
Dec 10, 2015, 5:41:23 AM12/10/15
to lif...@googlegroups.com, hede...@gmail.com
Can you live with multiple servers running different versions of your
software?

So that you could slowly migrate from one server to another by allowing
old "sessions" to stay on the old server, but direct new "sessions" to
the new instance.

The "old" and "new" sessions can be determined by looking at JSESSIONID
(if this cookie does not exist, it's a new session).

May that work?
--
Vasya Novikov

Viktor Hedefalk

unread,
Dec 10, 2015, 5:47:31 AM12/10/15
to Vasya Novikov, lif...@googlegroups.com
Yes, that's exactly what I'm looking for. In a perfect world I'd of course have zero-downtime INSTANT redeploy with new versions while keeping my entire heap :)

Actually I'm not really interested in load balancing (just yet) other than for just doing zero downtime. Since my app is written with lift and highly stateful I really need sessions to timeout before I can move the user to a new version.


Vasya Novikov

unread,
Dec 10, 2015, 6:29:10 AM12/10/15
to lif...@googlegroups.com, Viktor Hedefalk
Well, you can do that with nginx then. Nginx can proxy incoming requests
based on some cookie logic.

Example:
https://serverfault.com/questions/268633/controlling-nginx-proxy-target-using-a-cookie
--
Vasya Novikov

Viktor Hedefalk

unread,
Dec 10, 2015, 9:51:57 AM12/10/15
to Lift, hede...@gmail.com, n1m5-goo...@yandex.ru
Cool, thanks! 

Yeah, I almost could guess it would be kindof possible with nginx, but I'm really looking for a "just do this" kindof suggestion. I think my use case should be pretty common. I just want rolling releases of a stateful app with zero downtime without kicking out existing sessions. I'm trying to google this a lot but I don't want to re-invent something someone else has thought out better.

I'm looking at:

so one idea would be to do that + just have two nginx config files where all defaults go to A on one and all to B on the other and on each deploy you do a switch it out.

I'm still worrying though - every time I need to think too hard I think I shouldn't and should just google it better.

Thanks so far though, any additional tips highly appreciated!

Cheers,
Viktor

Viktor Hedefalk

unread,
Dec 10, 2015, 4:06:16 PM12/10/15
to Lift, n1m5-goo...@yandex.ru
I think I'm gonna go with HAProxy. I'll report back!

Vasya Novikov

unread,
Dec 10, 2015, 6:40:16 PM12/10/15
to Lift, Viktor Hedefalk
I do not actually see how switching will solve the problem.
The thing is: you want both instant reloads and statefullness.
So, if you switch all users from one server to another you use state (if
I understood the question correctly).

Still, I'm sorry, but I don't have any "just do this" solution. (Only a
path that _may_ work.)

Maybe someone else will help.
>> <javascript:>>
--
Vasya Novikov

Viktor Hedefalk

unread,
Dec 18, 2015, 7:45:32 AM12/18/15
to Lift, hede...@gmail.com, n1m5-goo...@yandex.ru
Hi,

I've successfully replaced all my nginx proxying stuff with haproxy and using free certs from letsencrypt. Pretty happy with haproxy so far!


"The thing is: you want both instant reloads and statefullness. "

No, I realize I can't have instant reloads - I just want instant zero fuzz fully automatic deploys. I realize current sessions need to stay with old version until timing out. Sorry if being unclear.

What I need is the following:

I want to be able to have one click deploys of new versions of my fully stateful lift webapps from say jenkins. Of course, since they are lift apps with state, I simply cannot remove the old version without messing up the experience for my users. So I need "drain mode". This seemed easier to setup in haproxy than in nginx (without premium) - that was the main reason for me switching.

haproxy seems to have the notion of drain mode in it's stickyness. So I can say: do round robin over my old version and new version of the app, but be sticky on this here session cookie but also put the old version in drain mode meaning no new sessions will go there. And when no sessions are left on the old version I can take it down. Rinse and repeat.

However, there are a lot of questions for me to fully automate this from a jenkins build.

Sorry if my original question was unclear. Reason I asked for help here is I know: 

1) We're all in the need for sticky sessions because lift.
2) Many people here have "full stack" knowledge and should have had to deal with similar issues.


Anyways, I'm working on it and I'll report back if/when I'm successful :)

Cheers,
Viktor

Joe Barnes

unread,
Jan 23, 2016, 4:27:10 PM1/23/16
to Lift, hede...@gmail.com, n1m5-goo...@yandex.ru
Hey Viktor,

Do you have any updates to report on this? At work we don't have smooth zero downtime yet because we're more focused on getting a good base of features that folks will care enough about to wish there was zero-downtime. :)

I was only aware of NGINX Plus for the purpose of session-draining.  I'd love to hear that you succeeded with haproxy.  I intend to set up a project (like this one showing how to deploy Lift in a Jetty cluster with packer and terraform) as an example for the rest of the community to reference.

Joe
Reply all
Reply to author
Forward
0 new messages