The topic of how to accomplish zero-downtime deployments with websockets seems to come up fairly frequently, especially recently. As products evolve or get created we see the move from a fairly historical use of HTTP requests to utilising websockets for numerous things. A couple of those use cases are signalling for WebRTC or sending real-time events down to users.
I've developed a fair few of these types of systems now and the question of how we're going to deal with deployments comes up. Do we deploy when no-one is using the service? This usually means an early start or a late night; that's no fun for anyone and doesn't feel very 'agile'. What happens when something goes horribly wrong and we have to deploy while users are using the service? It'll tell you what happens; chaos.
How do zero downtime deployments work with HTTP?
Let's take a step back: how do people achieve zero downtime deployments with HTTP? Well, HTTP requests have short lives; we send a request in and we get a response back from the server. Depending on your HTTP response times, the life of a HTTP request could be a couple of hundred milliseconds to many many seconds - those many many seconds could be anything up to the TIMEOUT
value in the browser; anything more than 60 and you're really cutting it fine with browser timeouts.
That means that we can expect that we would have to theoretically deal with a request for up to 60 seconds. A 60 second request seems like a complete nightmare to me and if any API I built had 60 second response times I would cry. But the point is, it's a finite number.
So one possible way to deal (there are many) with Zero Downtime deployments for a HTTP service would be to utilise Amazon's Elastic Load Balancer service. When setup to deal with HTTP traffic, you can remove a host that sits behind the ELB from the available list, wait until all the requests have finished being dealt with (with an upper limit of 60 seconds for example), deploy your latest code and restart the service and place it back inside the ELB's available list of hosts.