Introducing a new way to review your PRs.

Read the announcement

getredash / redash

Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data.

View on GitHub

20 documents · Updated Nov 11, 2026

docs / application-runtime

Application runtime and service composition

The Python application provides the web service and the operating tools that keep it running. It reads deployment settings, builds one configured Flask application, exposes that application through WSGI and the management CLI, and runs background work through Redis-backed queues. The same runtime also reports request, worker, queue, database, and Redis health so operators can see whether the service can accept work and complete it.

Runtime composition

The application is composed from shared service clients and Flask extensions. Startup connects the web layer to the database, Redis, mail, authentication, security, request metrics, API handlers, and background task context so one request can use the same service boundaries as the worker system.

The main assembly path is:

  1. redash.settings resolves process settings from the environment and loads enabled plug-ins.
  2. redash.create_app() creates the custom Flask application.
  3. The application attaches security, metrics, persistence, migration, mail, authentication, rate limiting, handlers, asset support, user support, and task support.
  4. redash/wsgi.py exposes the finished application for a WSGI server.

The process also applies the configured SQL parser grouping limits during startup. This lets operators control how much parser work a single statement can cause without changing the parser library.

When REMOTE_DEBUG is enabled, startup opens a remote debugger and waits for a debugger client before it continues. This mode is for an attached development session and can prevent a process from serving if no client connects.

This diagram shows how process settings become a running web service and how the web and worker paths share Redis and database services.

flowchart TD
    E[Environment settings] --> S[Runtime settings]
    S --> A[Application factory]
    A --> F[Configured Flask service]
    F --> W[WSGI entrypoint]
    F --> C[Management CLI]
    F --> T[Task context]
    T --> RQ[Redis queue service]
    F --> DB[Application database]
    RQ --> WK[Worker processes]
    WK --> DB

References: redash/…/__init__.py• L19-67 redash/__init__.py• L20-69 redash/app.py• L7-59 redash/wsgi.py• L1-3 redash/…/__init__.py• L29-31

Web service boundary

The web service accepts browser and API requests through Flask routes and resources. It gives each request access to the current user and organization, applies the configured security rules, and records request timing and query activity for operations. The /ping route provides a small unauthenticated liveness response, while /status.json exposes runtime status only to an authenticated super-admin.

The application can run behind a proxy. The runtime uses the configured proxy count to recover the client and host information that the security and request layers need.

References: redash/app.py• L7-23 redash/…/__init__.py• L11-22 redash/…/base.py• L18-61 redash/security.py• L23-70 redash/…/request.py• L12-54

Shared service clients

The runtime creates separate Redis clients for application state and for RQ, the Redis Queue system used for background work. It also creates the shared mail, database migration, rate limit, and StatsD metric services before the application factory attaches them. These clients are process-level resources, so web requests and task code use the same configured service endpoints within their process.

The application imports enabled query runners and notification destinations during startup. This makes those capabilities available to the web and task paths without changing the core application assembly.

References: redash/__init__.py• L5-16 redash/__init__.py• L45-69 redash/…/__init__.py• L355-389 redash/app.py• L25-60

Configuration boundary

Runtime configuration is the contract between deployment settings and every process that runs Redash. The settings layer converts environment values into database, Redis, security, feature, plug-in, and task options. It also requires the cookie secret at import time, so a process cannot start with an undefined signing key.

Configuration has two levels:

  • Static process settings control how a process connects to services and how it applies global security and feature rules.
  • Dynamic settings provide deployment-specific behavior such as extra periodic jobs and database extensions.

Read Configuration and organization settings for the full configuration model and organization-level overrides.

References: redash/…/__init__.py• L19-84 redash/…/__init__.py• L355-389 redash/…/__init__.py• L60-65 redash/…/database.py• L41-45

Startup requirements

The application needs a valid cookie secret before it can build the runtime. It also needs reachable database and Redis services for normal operation. Database setup is an explicit management action rather than an automatic side effect of every web startup.

Startup applies SQL parser grouping limits from configuration. If an operator lowers those limits, a statement that exceeds them can fail during parsing; a higher limit or zero removes that cap when the deployment requires it.

When Sentry is configured, startup enables error reporting for Flask, SQLAlchemy, Redis, and RQ. Query execution errors are excluded from that report path because they represent expected data-source failures rather than runtime faults.

References: redash/…/__init__.py• L30-63 redash/__init__.py• L45-59 redash/…/sentry.py• L12-41 redash/…/database.py• L21-31

WSGI and CLI entrypoints

The WSGI entrypoint serves the configured Flask application to a production WSGI server. The CLI entrypoint uses the same application factory and app context, so administrative actions see the same settings, models, extensions, and service clients as web requests.

The management surface groups commands by operational area:

Command areaPurpose
runserverRun the Flask development server.
databaseCreate or drop tables and re-encrypt protected data.
rqStart workers, start the scheduler, and run worker health checks.
users, groups, org, ds, queriesManage core application records and access settings.
status, check_settings, version, send_test_mail, shellInspect or verify the running setup.

The CLI is therefore an operations boundary, not a second application. Commands that touch application state run with the same Flask app context used by the web service.

References: manage.py• L1-9 redash/…/__init__.py• L20-45 redash/…/__init__.py• L47-90 redash/…/database.py• L48-125 redash/…/rq.py• L24-47

Database lifecycle

The database commands provide the controlled path for first-time schema creation and destructive schema removal. Initial creation checks the database, retries after a connection failure, loads configured extensions, creates the model schema, and marks it as current in the migration system. Later schema changes should use the migration lifecycle rather than recreate the database.

Protected configuration data can be re-encrypted through a separate command when the data encryption secret changes. The command reads the affected records with the old secret and writes them with the new one.

Read Data model and persistence lifecycle for the model layer, record relationships, and migration details.

References: redash/…/database.py• L21-45 redash/…/database.py• L48-75 redash/…/database.py• L77-125 redash/app.py• L49-52

Asynchronous execution

Background work runs through RQ queues backed by the RQ Redis connection. The rq CLI entrypoint starts a Redash worker or scheduler, while redash/worker.py defines the default queue groups and the common job interface. The default queue set covers operational jobs and query-related jobs, while deployments can pass a narrower queue list to split load across worker groups.

The worker adds three operating guarantees to queue execution:

  • Job creation and completion update StatsD counters by queue.
  • Jobs can be marked as cancelled and stopped by the worker.
  • A soft timeout and a hard timeout prevent a stuck child process from holding a worker forever.

Read Background jobs and scheduling for task routing, periodic work, query execution, alerts, and failure reporting.

References: redash/worker.py• L10-21 redash/…/worker.py• L25-71 redash/…/worker.py• L74-115 redash/…/worker.py• L194-200 redash/…/rq.py• L24-45

Scheduler operation

The scheduler maintains recurring work in the periodic queue. It builds the active schedule from built-in maintenance jobs and optional dynamic jobs, gives each definition a stable identity, removes jobs no longer present, and adds missing jobs before it starts its scheduling loop.

Recurring work includes query and schema refresh, stale schedule cleanup, user detail sync, failure reports, optional version checks, and optional query-result cleanup. The scheduler is a separate CLI mode from ordinary workers, but both use the same RQ connection and queue behavior.

References: redash/…/schedule.py• L24-32 redash/…/schedule.py• L35-55 redash/…/schedule.py• L57-116 redash/…/rq.py• L24-29

Worker supervision

The supplied Supervisor configuration runs one or more worker processes with automatic restart and a graceful termination signal. A periodic Supervisor event invokes the worker health check. The check treats a worker as healthy when it is busy, has sent a recent heartbeat, or has no jobs in its watched queues.

This design separates process supervision from queue status. Supervisor checks whether the process is alive and responsive, while the application status view reports queue depth, active jobs, worker state, and job totals.

References: worker.conf• L1-32 redash/…/rq.py• L48-96 redash/monitor.py• L85-119

Runtime monitoring

Monitoring combines request metrics, queue metrics, infrastructure status, and error reporting. Request hooks record duration and query use. Queue and worker metrics show whether asynchronous work is being created, run, finished, or failed. The status command and protected status endpoint combine these views with Redis memory, database size, and selected object counts.

This diagram shows the operational signals that meet at the status and monitoring boundaries.

flowchart LR
    HTTP[HTTP requests] --> RM[Request metrics]
    JOB[Queue jobs] --> QM[Queue metrics]
    PROC[Worker processes] --> HC[Supervisor health check]
    REDIS[Redis] --> ST[Runtime status]
    DB[Application database] --> ST
    QM --> ST
    PROC --> ST
    RM --> OBS[Logs and StatsD]
    QM --> OBS
    ERR[Runtime errors] --> SE[Sentry when enabled]
    ST --> CLI[status command]
    ST --> API[Protected status endpoint]

References: redash/…/request.py• L16-40 redash/…/worker.py• L37-71 redash/monitor.py• L10-58 redash/monitor.py• L61-119 redash/…/sentry.py• L26-44

Status surfaces

The status CLI command prints a JSON view for operators. The protected /status.json route returns the same status through the web service for super-admin users. Both surfaces include application version, Redis use, object counts, manager state, queue state, and database size metrics.

The /ping route has a narrower purpose. It confirms that the web process can answer a request but does not prove that the database, Redis queues, or workers are healthy.

References: redash/…/__init__.py• L53-55 redash/…/__init__.py• L11-22 redash/monitor.py• L10-58

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep redash/__init__.py remote-debug behavior aligned with deployment process settings. An enabled wait-for-client mode can stop web, CLI, scheduler, or worker startup.
  • Keep redash/__init__.py SQL parser limits aligned with the supported settings names and parser behavior. A setting change can turn valid long or nested statements into parse failures.
  • Keep redash/app.py extension setup aligned with any new shared service or request hook. A service that is created but not attached will fail only when its first request or task uses it.
  • Keep redash/worker.py, redash/…/worker.py, and redash/…/rq.py aligned when queue names or worker classes change. The CLI defaults and worker metrics must describe the same queue contract.
  • Keep redash/…/schedule.py aligned with dynamic settings when a periodic task changes its identity or interval. A changed identity can leave an old recurring job active.
  • Keep worker.conf aligned with the rq CLI command and the deployed queue environment. Supervisor can report a process as healthy while that process watches the wrong queues.
  • Keep the status command and /status.json authorization boundary intact when monitoring data changes. Runtime details must not become public through the liveness route.

Important failure modes

TriggerConsequenceGuard
REDASH_COOKIE_SECRET is missingSettings import fails and no application entrypoint starts.Set the required secret before starting web, CLI, scheduler, or worker processes.
REMOTE_DEBUG is enabled without an attached debuggerThe process waits during startup and does not serve requests or run commands.Enable it only for an intended debug session and attach the debugger before the process must operate.
SQL parser grouping limits are too low for a statementSQL parsing raises an error before the statement can run.Set the parser limits high enough for the deployment workload or use zero to remove the cap.
The database is not reachable during schema setupSetup waits once and then continues without a confirmed database connection.Check database reachability before running the database command and inspect its connection error.
A worker child ignores its soft timeoutThe worker can remain stuck and reduce query capacity.The hard-limit worker kills the child after the timeout and grace period.
A worker process has no recent heartbeat and has queued workSupervisor marks the worker unhealthy and can restart it.Inspect queue assignment, worker logs, and Redis connectivity.
A periodic job definition changes without schedule cleanupAn old job can continue to run beside the new job.Stable job identity and schedule reconciliation remove obsolete entries.
/ping is used as a full dependency checkA web process can appear healthy while queues or the database are unavailable.Use the protected status view and worker health check for dependency health.

Key files

FileWhy to read it
redash/app.pyShows the application factory and the order in which shared services attach to Flask.
redash/__init__.pyShows process-wide settings, optional remote debugging, logging, SQL parser limits, service clients, and plug-in loading.
redash/…/__init__.pyDefines the environment-to-runtime configuration boundary.
redash/wsgi.pyShows the WSGI production entrypoint.
manage.py and redash/…/__init__.pyShow the shared management entrypoint and command groups.
redash/…/database.pyShows schema setup, schema removal, database readiness checks, and protected-data re-encryption.
redash/…/rq.pyShows worker, scheduler, queue selection, and health-check operation.
redash/worker.pyDefines default queue groups, the shared job interface, and job log context.
redash/…/worker.pyDefines queue, cancellation, metrics, and timeout behavior.
redash/…/schedule.pyDefines recurring job reconciliation and scheduler operation.
redash/monitor.pyDefines the data used by runtime status surfaces.
worker.confShows process supervision and the deployed worker health-check loop.