Service dependencies
Services rarely run alone. An API needs a database. A worker needs a queue. Rune lets you express that as data, not bash.
Declare a dependency
Section titled “Declare a dependency”service: name: api image: ghcr.io/example/api:1.0.0 scale: 2
dependencies: - service: postgres readyWhen: healthy - service: redis readyWhen: running - service: auth namespace: shared readyWhen: healthy timeoutSeconds: 60| Field | Notes |
|---|---|
service | The name of the dependency. |
namespace | Optional. Defaults to the dependent’s namespace. |
readyWhen | running, healthy (probes pass), or started (process up). |
timeoutSeconds | How long to wait before declaring the dependency unsatisfied. |
optional | If true, the dependent rolls out even if the dependency isn’t ready. |
What it does
Section titled “What it does”On rollout (cast or scale), the reconciler:
- Resolves the dependency graph.
- Waits for each dependency to reach
readyWhen(with the configured timeout). - Starts the dependent service only after all required dependencies are satisfied.
If a dependency cycle exists, rune cast rejects the spec.
Inspecting
Section titled “Inspecting”rune deps graph apiRenders the dependency graph for api, including transitive deps.
rune deps check apiReports current readiness status of each dependency.
rune deps validate apiValidates the dependency definitions in the spec without applying.
rune deps dependents postgresLists services that depend on postgres. Useful before deleting a database.
Updates
Section titled “Updates”When a dependency restarts, dependents are not automatically restarted. Most services tolerate transient dependency blips and reconnect on their own. If yours doesn’t, you have two options:
- Fix the service to reconnect (preferred).
- Cascade restart manually:
rune restart apiafter arune restart postgres.
Optional dependencies
Section titled “Optional dependencies”dependencies: - service: optional-cache readyWhen: running optional: trueThe dependent rolls out even if optional-cache is missing or failing. Useful for graceful degradation.
Anti-patterns
Section titled “Anti-patterns”- Deep dependency chains. A → B → C → D → E means a single slow service stalls the whole stack. Try to keep depth ≤ 2.
- Circular dependencies. Rejected by the linter. If you think you need one, you don’t — invert the dependency or split a service.
- Using deps for ordering only. If service B doesn’t actually need A to be healthy, leave the dependency off. Rune will start them in parallel — usually faster.