Skip to main content
To support zero-downtime deployments, configure a health check endpoint in your Flask application. This endpoint allows Sevalla to verify that your app is running correctly before routing traffic to it. There are multiple ways to implement a health check in Flask, depending on the level of control and visibility required.

Option 1: Use an existing view

If you don’t want to add a separate health check route, you can reuse an existing public view in your application. The selected view should fail with an error if a critical dependency, such as the database or another essential service, is unavailable.

Option 2: Use a dedicated health check view

A dedicated health check route provides a clear and explicit way to verify your app’s health. A simple implementation can execute a lightweight query like session.execute(text("SELECT 1")) to confirm the database is reachable. If the connection fails, an exception will be raised, and the route will return an error.
from sqlalchemy import text

from .extensions import db

@app.route("/health_check")
def health_check():
    with db.sessionmaker() as session:
        session.execute(text("SELECT 1"))
    return "OK"
You can extend this route with additional checks (such as cache or queue connectivity) as your application grows.

Option 3: Use a health check library

Several libraries can help you implement comprehensive health checks for databases, task queues, caches, email services, and more. One such option is Healthcheck, which simplifies defining and managing these checks in a single place.