We have an API server, which serves both of our web app and mobile app (both Android, IOS).

We have to shut down database servers sometimes for up-gradation or maintenance, so the site shows Maintenance in Progress kind of page.

It works for the web app, but what to do about the mobile app? We can't show any kind of maintenance board on the app to stop the app calling APIs, so all requests on mobile app ends up with no response from API server and fail. How this scenario is handled? What is the common practice?

  • 2
    "We can't show any kind of maintenance board on the app to stop the app calling APIs" Why not? – Philip Kendall Apr 3 '17 at 7:07
  • 4
    Talk to whoever does have control of it. Don't be stuck in a little silo of "here's the code I write". – Philip Kendall Apr 3 '17 at 7:11
  • 3
    This should have been handled before deploying the app - correctly handling HTTP status codes to display a service unavailable message. Status code 503 is the appropriate code to tell an app the resource is down for maintenance, overloaded, or otherwise unavailable. See the definition here. The server should then handle all API requests with a 503 response. – Ivo Coumans Apr 3 '17 at 7:46
  • 7
    its 2017, get a failover db server and upgrade one at a time for gods sake – Ewan Apr 3 '17 at 9:30
  • 1
    @Ewan Easy mate, if I had known it all why would I ask it? – Shaharyar Apr 3 '17 at 12:28

For the future, I would suggest you make sure that your server returns a 503 status when it is in maintenance, do your best to make it return a 503 status when there is unexpected trouble, and make sure your mobile apps handle this well.

Right now I suggest you do some serious testing how your mobile apps behave if there is a 503 error. If it causes serious trouble then update the apps, and don't do the maintenance until most users use an app version that will be well behaved. If it causes trouble but not fatal, you discuss with your management whether you can do the maintenance. You may want to do maintenance in the night when fewer users are affected.

  • Yeah, this seems like a good approach. – Robert Harvey Apr 3 '17 at 19:54
  • I didn't think about maintenance while building the app, should've thought earlier. Thanks for the suggestion about app update. – Shaharyar Apr 5 '17 at 5:23

In this case you should edit your mobile app, so when i get's a 503 it will display the correct message such as "Under Maintenance, come back in 15 min".

Also, since your upgrading/replacing/whatever your databases, you don't need to turn off the api endpoints, you just need to have a switch that will check for maintenance hours/undergoing and respond accordantly...


Ideally you'd want to upgrade with zero downtime, but if you absolutely can't:

Make this part of your API. Add a call that simply returns a status and a message. Direct clients to make this call before making any other calls (ie. at app start), and to display your message if the server is down for maintenance. Once this is done, it could be handled in many different ways on the server side (e.g. redirect to a server that returns hard-coded values, and hosts your "down for maintenance" page).

If the server is completely down, the clients get a timeout on the first call, and this gives them a chance to gracefully handle that. If the server is up but in some kind of maintenance, it gives the user some info about what's going on.

Note that this will only help new clients. If a client is already connected, the only way to remedy this is to add some kind of complex status return to each and every call.

  • 2
    Direct clients to make this call before making any other calls -- Congratulations. You just doubled the API overhead. – Robert Harvey Apr 3 '17 at 19:11
  • @Robert Harvey Read the last paragraph again. True, I could have been clearer in the 1st paragraph, the last one paragraph should have made it clear. – HiredMind Apr 3 '17 at 19:51
  • You'd have to stand up a proxy service to serve status when the original service is down. – Robert Harvey Apr 3 '17 at 19:53
  • @Robert Harvey True. But even in its absence, if the "Are you alive?" call fails, that in itself has a special meaning that the client can use to fail gracefully. – HiredMind Apr 3 '17 at 20:04
  • Depending on the concurrency just the AyA request thing may know down the workers of the server (during a peak, for example). Basically 50% of the traffic is asking ti the server: Are you ok? Rather let your request fail, retry 1-2 times and finally show the error if nothing happens. – Laiv Apr 3 '17 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.