Webserver and workspace
The Dagster webserver is the Python service that joins a Dagster instance to the browser. It loads one or more code locations into a workspace, exposes their state through the GraphQL API, and serves the compiled Dagster UI and its assets. See User interfaces, GraphQL API, and Dagster UI for the related product views.
System boundary
The webserver coordinates three parts of one user flow:
- The workspace gives the server the code locations that define assets, jobs, schedules, and sensors.
- The GraphQL API gives the UI a typed way to read state and request actions.
- The UI assets give the browser the HTML, JavaScript, styles, and images needed to present that state.
The server also uses the Dagster instance for persistent run and event data. It does not replace the daemon or the code that defines a user's jobs. It provides the shared view and control point for those systems.
Webserver startup
Startup sequence
The dagster-webserver command is the main process entry point. It selects a workspace target, opens the Dagster instance, creates a process-scoped workspace, builds the ASGI web application, and starts Uvicorn to serve HTTP and WebSocket traffic. The process stays alive while the workspace owns its code-location connections.
The startup flow is:
- Read server options and workspace options from the command line or their supported environment variables.
- Open the Dagster instance and tune it for a long-running webserver process.
- Create the workspace process context from the selected load target.
- Build the webserver application with that context.
- Choose the requested port or a free port when the default is already in use.
- Start the ASGI server.
This diagram shows how startup connects the command line to the browser-facing service.
flowchart LR
A[dagster-webserver] --> B[Server and workspace options]
B --> C[Dagster instance]
C --> D[Workspace process context]
D --> E[Webserver ASGI app]
E --> F[Uvicorn]
F --> G[HTTP and WebSocket clients]
References: python_modules/…/__main__.py• L1-3 python_modules/…/cli.py• L49-78 python_modules/…/cli.py• L222-268 python_modules/…/cli.py• L284-323
Server lifetime
The workspace process context remains open for the full server lifetime. On shutdown, it stops its location watchers and cleans up the loaded code locations before the process exits. This keeps code-location resources tied to the same lifetime as the webserver that uses them.
The server can run in read-only mode. In that mode, the request context reports permissions that prevent state-changing actions such as launching runs or changing schedules.
References: python_modules/…/context.py• L948-1015 python_modules/…/context.py• L1298-1351 python_modules/…/context.py• L835-865 python_modules/…/cli.py• L136-142
Workspace loading
Workspace load targets
A workspace is the server's current set of code locations. A code location is a named source of Dagster definitions that the server can inspect and address as one unit. A workspace load target describes how to find those locations.
The command selects one target type. The common choices are a workspace YAML file, a Python file, a Python module or package, or an already running gRPC server. A pyproject.toml project configuration can also supply a module or an autoloaded definitions target. Several targets can be combined when the user needs more than one location.
The target becomes a set of code-location origins. The workspace process then loads each origin and records its current status for later requests.
References: python_modules/…/cli_target.py• L52-85 python_modules/…/cli_target.py• L89-123 python_modules/…/cli_target.py• L134-232 python_modules/…/load_target.py• L23-58 python_modules/…/load_target.py• L100-180 python_modules/…/load_target.py• L183-277
Code-location isolation
Python-backed locations normally run behind managed gRPC code servers. A gRPC-backed location lets the webserver use definitions from a separate Python environment while the webserver keeps one stable process for browser requests. An externally hosted gRPC location follows the same boundary without the webserver starting its process.
This separation lets one location fail or use different dependencies without making the webserver load all user code into its own process. The workspace still presents the locations together to the UI.
References: python_modules/…/load_target.py• L184-251 python_modules/…/context.py• L993-1015 docs/…/workspace-yaml.md• L17-27
Request contexts
A request context is a fixed view of the workspace for one HTTP request or WebSocket operation. The process context owns the live workspace, while the request context holds the workspace snapshot and the Dagster instance used by GraphQL resolvers and other endpoints.
The server creates a request context before it reads workspace data. This boundary prevents a request from using a location while the process context is replacing or cleaning up that location. It also gives each request its own loaders and permission checks.
References: python_modules/…/context.py• L114-153 python_modules/…/context.py• L769-875 python_modules/…/context.py• L1309-1317 python_modules/…/webserver.py• L77-84
Workspace refresh
The process context can reload the code in every location or refresh the server's view of a remote location. It swaps the current workspace as one unit, starts watchers for new gRPC locations, and cleans up old locations after the swap.
Location state events can trigger a refresh without restarting the webserver. The UI can therefore see updated definitions or a location error through a later request while the HTTP service stays available.
References: python_modules/…/context.py• L1267-1351
Request serving
ASGI route surface
The webserver builds one ASGI application with middleware and routes. The route surface combines the GraphQL API, static UI resources, the UI entry page, and a small set of browser-facing downloads and asset event endpoints.
The path prefix is part of this boundary. When configured, the server mounts its routes below that prefix and redirects the root path to it. The same prefix is inserted into UI and GraphiQL URLs so that the browser addresses the API and assets at the same public location.
References: python_modules/…/app.py• L10-37 python_modules/…/webserver.py• L299-365 python_modules/…/cli.py• L97-103
UI asset delivery
The root UI request returns the built index.html from the webserver package. Before sending it, the server fills in deployment values such as the path prefix, instance identifier, telemetry setting, and live-data polling rate. It also adds browser security headers.
Other files under the UI build directory are served as static files. This includes the JavaScript bundle, styles, images, and files used by the GraphiQL page. The webserver package declares this build directory as a shipped artifact, so a package without the built UI cannot serve the main UI page.
References: python_modules/…/webserver.py• L205-249 python_modules/…/webserver.py• L251-292 python_modules/…/pyproject.toml• L24-32
GraphQL HTTP requests
GraphQL is the main data interface between the browser and the Dagster system. The server accepts queries through GET and POST requests at /graphql, reads the query and optional variables, then executes the query against the schema with the current request context.
The request path has three high-level stages:
- Parse the query and reject invalid syntax.
- Validate the query against the GraphQL schema.
- Execute resolvers with the workspace request context and return data or structured errors.
The schema exposes query, mutation, and subscription roots. Queries read deployment state. Mutations request actions. The resolver layer uses the request context to connect those operations to the instance and code locations.
References: python_modules/…/graphql.py• L112-174 python_modules/…/graphql.py• L234-328 python_modules/…/__init__.py• L82-88
GraphQL subscriptions
Subscriptions provide live updates for data such as run events and captured logs. The browser opens a WebSocket at the same /graphql path, selects the graphql-ws protocol, and starts named operations on that connection.
The server acknowledges the connection, starts each accepted subscription, sends data messages as results arrive, and sends a completion message when the stream ends. It cancels active subscription tasks when the client stops an operation or disconnects.
This channel complements normal polling. The UI uses ordinary GraphQL requests for point-in-time data and subscriptions when it needs a stream of new events.
References: python_modules/…/graphql.py• L176-232 python_modules/…/graphql.py• L330-362 python_modules/…/graphql.py• L403-445 python_modules/…/graphiql.py• L62-80
Supporting browser endpoints
The server provides a few paths that support UI actions outside the GraphQL response body. These paths let the browser download captured logs or debug data, render notebooks, report asset materializations, observations, and check evaluations, and read server version information.
These endpoints still create a request context when they need instance or code-location data. Asset event reporting writes to the instance and is rejected in read-only mode, so these paths follow the same workspace and permission boundary as GraphQL requests.
References: python_modules/…/webserver.py• L110-203 python_modules/…/webserver.py• L318-350 python_modules/…/test_asset_events.py• L21-65 python_modules/…/test_asset_events.py• L202-301 python_modules/…/test_asset_events.py• L312-396
Browser and server coordination
UI data lifecycle
The browser first loads the UI shell and its static assets. The shell then uses the configured path prefix to send GraphQL operations to the Python server. The server resolves those operations against the current workspace and instance, and the UI turns the returned state into pages for assets, jobs, runs, schedules, sensors, and other Dagster objects.
The coordination flow is:
- The browser requests the UI entry page.
- The server injects deployment values and returns the HTML shell.
- The browser loads the UI assets.
- The UI sends GraphQL queries or mutations for current state and user actions.
- The server creates a request context and resolves the operation through the GraphQL schema.
- The UI updates from the response or from subscription events.
This diagram shows the relationship between the browser, the Python server, the GraphQL layer, and the workspace.
sequenceDiagram
participant UI as Browser UI
participant WS as Python webserver
participant GQL as GraphQL API
participant W as Workspace
participant I as Dagster instance
UI->>WS: Request HTML and static assets
WS-->>UI: UI shell and assets
UI->>GQL: Query or mutation
GQL->>W: Read code-location state
GQL->>I: Read or change stored state
W-->>GQL: Definitions and location state
I-->>GQL: Runs and event data
GQL-->>UI: GraphQL response
UI->>GQL: WebSocket subscription
GQL-->>UI: Live event data
References: python_modules/…/webserver.py• L205-240 python_modules/…/graphql.py• L258-328 python_modules/…/context.py• L1309-1317 docs/…/webserver.md• L7-25
Change checklist
When these files or sections are changed, remember to consider these:
- When changing workspace target rules, check that CLI options, workspace-file loading, project defaults, and code-location names still produce the same set of origins.
- When changing the public path prefix, check the route mount, the injected UI asset prefix, and the GraphiQL HTTP and WebSocket URLs together.
- When changing the GraphQL schema roots or request context, check both HTTP execution and WebSocket subscription execution.
- When changing UI build output or package artifacts, check that the root HTML, static files, and GraphiQL vendor files are shipped at the paths the routes expect.
- When changing workspace refresh behavior, check that in-flight requests keep a valid snapshot while old locations and their watchers are closed.
- When changing asset event endpoint inputs or permissions, check that the external asset reporting contract and read-only behavior stay aligned.
- When changing the webserver package dependency set or supported Python range, check that the ASGI server, GraphQL layer, and packaged UI still resolve and start together.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No valid workspace target is found | Startup stops before the webserver can serve the UI | Supply one supported target or configure the project/workspace default. |
| A code location cannot load or its gRPC server becomes unavailable | The workspace reports a location error and requests for that location cannot return its definitions | Check the location status and refresh or reload the location after fixing its environment. |
| The packaged UI build is missing | The root UI request fails instead of returning the application shell | Build or restore the webserver UI artifacts before serving the package. |
| Public path prefix and browser asset paths do not match | The HTML may load while API, static asset, or WebSocket requests go to the wrong URL | Use the same prefix for route mounting and injected client URLs. |
| A GraphQL query has invalid syntax or fields | The request returns a client error instead of data | Validate the query against the active schema before execution. |
| A resolver raises a server error | The response includes error details and uses a server-error status | Inspect the GraphQL error payload and the affected workspace or instance operation. |
| A client closes a subscription connection | Active subscription work is canceled and no more live events reach that client | Reconnect and start the subscription again when live updates are needed. |
| A read-only client reports an asset event | The endpoint returns authorization failure and does not write the event | Use a writable deployment for asset event reporting. |
| Asset event payload shape or asset-key encoding is invalid | The endpoint returns a client error and does not store the requested event | Send the supported JSON or query parameters and encode keys with embedded slashes in the request body or query. |
| The webserver package resolves incompatible runtime dependencies | The service may fail during install or startup before it can serve requests | Keep the declared dependency constraints and lock resolution aligned with the supported Python range. |
Key files
| File | Why to read it |
|---|---|
| python_modules/…/cli.py | Shows command-line startup, instance setup, workspace creation, port selection, and Uvicorn startup. |
| python_modules/…/pyproject.toml | Defines the webserver entry points, runtime boundary, supported Python range, GraphQL and ASGI dependencies, and shipped UI artifact. |
| python_modules/…/uv.lock | Records the resolved webserver, GraphQL, ASGI, and local Dagster package dependency graph used for a repeatable environment. |
| python_modules/…/app.py | Shows how a workspace process context becomes the browser-facing ASGI application. |
| python_modules/…/webserver.py | Shows the route surface, UI asset delivery, path-prefix handling, and request-context use. |
| python_modules/…/graphql.py | Shows GraphQL HTTP execution, WebSocket subscriptions, error handling, and request boundaries. |
| python_modules/…/context.py | Shows the process-scoped workspace, request snapshots, code-location refresh, permission boundary, and cleanup lifecycle. |
| python_modules/…/load_target.py | Shows the supported ways to describe code-location sources, including project configuration targets, before they are loaded. |
| python_modules/…/load.py | Shows how workspace configuration becomes code-location origins. |
| python_modules/…/__init__.py | Shows the GraphQL schema boundary used by the webserver. |
| python_modules/…/graphiql.py | Shows how the built-in GraphiQL page addresses HTTP and WebSocket GraphQL endpoints. |
| python_modules/…/test_asset_events.py | Shows the browser-facing asset event contract and its read-only authorization boundary. |