Home > Mobile >  Spring boot block requests for maintenance and return 503 error on each requests
Spring boot block requests for maintenance and return 503 error on each requests

Time:09-09

how I can do in order to return 503 server error response code when my api is under maintenance?

CodePudding user response:

Assuming your Spring Boot web service is down completely for maintenance, then its best not to do it at the Spring Boot level. Perhaps its better to come up with a solution in by which you can swap out the server for something else that returns the 503.

Heres a very simple example:

  • Your APIs domain is api.myservice.com
  • You then switch where the domain is pointing to that solution that statically responds with the 503.
  • You do the maintenance on the server/database/etc.
  • Once the maintenance is done and your Spring Boot service is up and running, you then switch your domain to point back to the server.

Note: Domains records have a Time To Live so note that the above example is just something to give you an idea. You'll have to take the timing into consideration. An actual solution is hard to recommend when we don't have your environment details or context.

The point I'm trying to make is that perhaps Spring Boot is usually not the place to do this.

CodePudding user response:

Usually microservices tend to have a API gateway where you implement solutions such parsing some header token and inserting new headers , rate limiting , checks like if a user is administrator or not etc

https://docs.microsoft.com/en-us/dotnet/architecture/microservices/architect-microservice-container-applications/direct-client-to-microservice-communication-versus-the-api-gateway-pattern

You can use https://spring.io/projects/spring-cloud-gateway which is used build API gateway based on spring stack

I believe you can use this to temporarily shutdown certain routes and also configure different errors

  • Related