Introducing a new way to review your PRs.

Read the announcement

hatchet-dev / hatchet

🪓 An orchestration engine for background tasks, AI agents, and durable workflows

View on GitHub

31 documents · Updated Nov 23, 2026

docs / olap-and-observability-services

OLAP and observability services

The OLAP and observability services turn workflow activity into durable run views and monitoring signals. They give the API, console, operators, alerting, and telemetry systems a shared view of workflow history without making those consumers read live execution state.

System role

The OLAP service stores workflow runs, task events, statuses, event links, payloads, and trace data in a queryable view. Related metrics, alerts, and telemetry services read this view to show run health, queue pressure, service health, execution traces, and recent failures. The service runtime and control plane provides the parent system view; task and scheduling controllers and telemetry analytics and usage describe related activity and downstream signal processing.

Activity projection

An activity projection is the durable operational view built from workflow activity. It supports both workflow-run views and task-run views, so a client can inspect a whole workflow or one task through the same analytical boundary. The repository contract covers run lists, event history, status counts, timing data, event links, payload reads, and trace lookup. (pkg/…/olap.go• L272-343)

The projection keeps tenant identity with each view. It also keeps the identifiers and timestamps needed to connect a task to its workflow run and to find payloads or traces later. (pkg/…/olap.go• L137-163, pkg/…/olap.sql• L265-346)

References: pkg/…/olap.go• L137-163 pkg/…/olap.go• L272-343 pkg/…/olap.sql• L265-346

Analytical lifecycle

The analytical lifecycle moves activity into a durable view, reconciles derived status, and exposes read paths for clients, alerts, and monitoring.

This diagram shows the relationship between workflow activity and the views that downstream systems use.

flowchart LR
    A[Workflow activity] --> B[OLAP activity view]
    B --> C[Run and task history]
    B --> D[Status and count views]
    B --> E[Metrics and alerts]
    B --> F[Trace views]

The service also manages the data window for these views. It creates current and near-future partitions, removes data beyond retention, refreshes database statistics, and moves old inline payloads to an external store when that store is enabled. (pkg/…/olap.go• L430-610, pkg/…/olap.go• L3524-3627, pkg/…/olap.sql• L1-28, pkg/…/olap.sql• L69-226)

References: pkg/…/olap.go• L430-610 pkg/…/olap.go• L3524-3627 pkg/…/olap.sql• L1-28 pkg/…/olap.sql• L69-226

Controller lifecycle

The OLAP controller consumes tenant-scoped activity from the OLAP queue and starts the status, aggregate, alert, partition, audit, and maintenance work that keeps the analytical view current. It also starts optional Prometheus update workers and stops these workers with the queue and scheduler. (internal/…/controller.go• L337-528)

The controller schedules recurring work with jitter and singleton execution. This spreads load across controller instances and prevents overlapping runs of the same maintenance job. It accepts created tasks and workflow runs, monitoring events, event triggers, webhook validation failures, and CEL evaluation failures. It can use a stable workflow-run sampling decision for these writes and for the spans created from the same activity. (internal/…/controller.go• L378-463, internal/…/controller.go• L531-579, internal/…/controller.go• L581-755, internal/…/controller.go• L773-863, internal/…/controller.go• L985-1349)

References: internal/…/controller.go• L337-528 internal/…/controller.go• L378-463 internal/…/controller.go• L531-579 internal/…/controller.go• L581-755 internal/…/controller.go• L773-863 internal/…/controller.go• L985-1349

Audit log archival

Audit log archival moves old audit records out of the live OLAP store while keeping them as tenant-scoped files for later use. An hourly OLAP controller considers partitions that ended at least 24 hours earlier; when an archive store is configured, it uploads each tenant's records in bounded files, then removes the database partition and marks it complete. (internal/…/archive_audit_logs.go• L11-41, internal/…/controller.go• L392-404, pkg/…/olap_audit_log_archive.go• L21-98)

The archive process uses a lease and a saved cursor for each partition. This gives one process ownership of the work and lets a later run resume after an interruption. It does not remove a partition until its files are stored, so an upload or lock error leaves the source data available for a later run. (pkg/…/olap_audit_log_archive.go• L101-175, pkg/…/olap_audit_log_archive.go• L186-253, pkg/…/olap.sql• L230-316)

References: internal/…/archive_audit_logs.go• L11-41 internal/…/controller.go• L392-404 pkg/…/olap_audit_log_archive.go• L21-98 pkg/…/olap_audit_log_archive.go• L101-175 pkg/…/olap_audit_log_archive.go• L186-253 pkg/…/olap.sql• L230-316

Run views and status processing

Status processing turns many task events into a small set of readable states. It then uses those states to update workflow views and publish signals for consumers that need to react to final results.

Readable statuses

The readable status is the stable state shown to clients and monitoring systems. It groups detailed execution events into QUEUED, RUNNING, COMPLETED, CANCELLED, FAILED, and EVICTED. The status rules favor the highest state reached within the current retry and always record a newer retry even when its readable state does not change. (pkg/…/olap.go• L206-230, pkg/…/olap.go• L1791-1827, pkg/…/olap.sql• L794-967, pkg/…/olap.sql• L1044-1118)

This rule matters because event order can vary. A later event from a newer retry must advance the run's retry state before older-looking events from that retry are applied. A completion that arrives before queueing for the same retry must not later regress the run to RUNNING. A failure from an attempt that will retry is recorded in history but does not make the task or its workflow terminal. (pkg/…/olap.go• L1797-1827, pkg/…/olap_status_update_test.go• L205-261, pkg/…/olap_status_update_test.go• L356-428)

References: pkg/…/olap.go• L206-230 pkg/…/olap.go• L1791-1827 pkg/…/olap.go• L1960-1987 pkg/…/olap.sql• L794-967 pkg/…/olap.sql• L1044-1118 pkg/…/olap_status_update_test.go• L205-261 pkg/…/olap_status_update_test.go• L356-428

Workflow status derivation

A workflow run status is derived from the states of its child tasks. The view remains RUNNING while work is missing, queued, or active. It becomes EVICTED when all expected tasks are evicted, and it becomes failed, cancelled, or completed when the matching final condition is reached. (pkg/…/olap.sql• L1120-1205, pkg/…/olap.sql• L1227-1472)

This makes task state the source of workflow progress while preserving a workflow-level result for clients. Operator-managed workflows use a self-link to expose orchestrator timing and error data without using that hidden task as a source for workflow status. (pkg/…/olap.sql• L434-455, pkg/…/olap.sql• L1127-1137)

References: pkg/…/olap.sql• L1120-1205 pkg/…/olap.sql• L1227-1472 pkg/…/olap.sql• L434-455

Run history

Run history is the read model for operational inspection. It supports filtered and paged task or workflow-run lists, event history, duration data, status counts, trigger links, metadata filters, and optional input or output payloads. Workflow-run reads combine run metadata with child task data and select the latest child output when a workflow has several completed children. A separate read path selects failed runs by their finished time so alert processing can inspect a bounded time window. (pkg/…/olap.go• L889-980, pkg/…/olap.go• L1304-1377, pkg/…/olap.sql• L348-466, pkg/…/olap.sql• L1474-1588, pkg/…/olap.sql• L1879-1889, pkg/…/olap_list_workflow_runs_test.go• L127-182)

The view also supports event-centric inspection. Event lists can be filtered by key, time, workflow, run identifier, metadata, status, and scope. Event links connect an event to the runs that it triggered. (pkg/…/olap.sql• L1980-2107)

References: pkg/…/olap.go• L889-980 pkg/…/olap.go• L1304-1377 pkg/…/olap.sql• L348-466 pkg/…/olap.sql• L1474-1588 pkg/…/olap.sql• L1879-1889 pkg/…/olap_list_workflow_runs_test.go• L127-182 pkg/…/olap.sql• L1980-2107

Payload lifecycle

Payloads let run views expose workflow input and output without forcing all payload data to stay in the main analytical tables. New payloads are stored inline first. After the inline retention window, the service can copy them to an external store and keep a block index that maps payload identifiers to external objects. (pkg/…/olap.go• L3350-3676, pkg/…/olap.sql• L2231-2266, pkg/…/olap.sql• L2326-2459)

The read path uses the OLAP copy first for unreferenced payloads and falls back to the core payload store when the OLAP copy is absent. Referenced payloads are read from the core store, and task output is decoded from the completion-event shape before it is returned to callers. (pkg/…/olap.go• L3416-3462, pkg/…/olap.go• L3484-3676)

References: pkg/…/olap.go• L3350-3676 pkg/…/olap.go• L3416-3462 pkg/…/olap.sql• L2231-2266 pkg/…/olap.sql• L2326-2459

Metrics and monitoring signals

Metrics processing turns operational views into signals for tenant dashboards and platform health checks. The signals cover workflow outcomes, execution timing, queue pressure, status-update backlog, database health, worker capacity, and tenant failure alerts.

Workflow metrics

Workflow metrics summarize terminal task and workflow updates. They can provide duration data and outcome counts for a tenant while remaining separate from the main status update path. The analytical queries also provide time-bucketed completed and failed counts and filtered status totals for run dashboards. (pkg/…/olap.sql• L1570-1649, pkg/…/olap.sql• L1587-1829)

Status totals retain an evicted count while presenting evicted work with the running view. This gives users a useful active-work count without hiding work that may return after durable restore. (pkg/…/olap.go• L1723-1788, pkg/…/olap.sql• L1587-1649)

References: pkg/…/olap.sql• L1570-1649 pkg/…/olap.sql• L1587-1829 pkg/…/olap.go• L1723-1788

Failure alerts

Failure alerts turn newly finished failed workflow runs into tenant notifications. The alert process checks whether alerts are active for each tenant, reads a bounded window from the OLAP run view, and sends the matching runs to the alert service. (internal/…/process_alerts.go• L13-29, internal/…/process_alerts.go• L33-74)

The window starts from the tenant's last alert time and extends to a point one minute behind the current time. The delay allows a run whose finish time is written before its transaction commits to become visible before the query advances. The process limits one batch to 1,000 runs and uses a 24-hour lower bound when the tenant has no recent alert time. (internal/…/process_alerts.go• L52-68, pkg/…/olap.sql• L1879-1889)

References: internal/…/process_alerts.go• L13-29 internal/…/process_alerts.go• L33-74 pkg/…/olap.go• L290 pkg/…/olap.go• L1347-1377 pkg/…/olap.sql• L1879-1889

Time-bucket aggregates

Time-bucket aggregates provide fast minute-level views of task statuses, task events, and incoming events. Source writes produce aggregate rows and temporary delta rows. The combined result stays equal to the source data while compaction runs, and the aggregate rows alone become complete after compaction catches up. This remains true across concurrent source writes, deletes, and rolled-back transactions. (pkg/…/olap_aggregates_test.go• L26-79, pkg/…/olap_aggregates_test.go• L103-247, pkg/…/olap_aggregates_test.go• L314-357)

The metrics read path can use raw rows for periods before aggregates are complete. This keeps older metric windows readable while the aggregate boundary moves forward. (pkg/…/olap.go• L412-420, pkg/…/olap.go• L1723-1751, pkg/…/olap.go• L2759-2784)

References: pkg/…/olap.go• L412-420 pkg/…/olap.go• L1723-1751 pkg/…/olap.go• L2759-2784 pkg/…/olap_aggregates_test.go• L26-79 pkg/…/olap_aggregates_test.go• L103-247 pkg/…/olap_aggregates_test.go• L314-357

Platform health signals

Platform health signals show whether the analytical and execution systems can keep up. The repository exposes the size of task and workflow status-update backlogs and the count of runs by status for the prior day. These values support scheduled service metrics and help distinguish workflow failure from processing delay. (pkg/…/olap.go• L3908-3930, pkg/…/olap.sql• L2295-2310)

The same monitoring surface can include database maintenance state. Table analysis and partition statistics keep query planning and retention work observable instead of treating the OLAP store as a black box. (pkg/…/olap.go• L3679-3819, pkg/…/olap.sql• L30-67, pkg/…/olap.sql• L2312-2324)

References: pkg/…/olap.go• L3679-3819 pkg/…/olap.go• L3908-3930 pkg/…/olap.sql• L30-67 pkg/…/olap.sql• L2295-2324

Trace and telemetry views

Trace processing connects a workflow run to the spans that explain its execution. Engine activity and externally submitted OpenTelemetry spans can share a tenant-scoped trace view, while exported metrics and traces carry service identity and deployment context to a collector.

Trace correlation

The repository stores spans and lookup entries together. A lookup from a workflow-run identifier returns the trace identifier that clients need to open the related spans. Stable derived identifiers give engine-created workflow traces a consistent root across separate activity records. (pkg/…/olap.go• L340-343, pkg/…/olap.go• L3916-3922, pkg/…/olap.go• L3973-4225)

The trace view can therefore join engine spans with SDK or user spans without requiring every consumer to understand how each span entered the system. The controller also creates root spans for new task and workflow-run records and event or task spans after the related OLAP write succeeds. (internal/…/controller.go• L650-755, internal/…/controller.go• L866-923, internal/…/controller.go• L1200-1267)

References: internal/…/controller.go• L650-755 internal/…/controller.go• L866-923 internal/…/controller.go• L1200-1267 pkg/…/olap.go• L340-343 pkg/…/olap.go• L3916-3922 pkg/…/olap.go• L3973-4225

Collector export

The telemetry service sends traces and metrics to an OpenTelemetry Protocol collector when a collector endpoint is configured. It adds service and deployment identity to both signal types, supports secure or insecure transport, and can attach an authorization value for the collector. (pkg/…/telemetry.go• L27-33, pkg/…/telemetry.go• L35-110, pkg/…/telemetry.go• L113-186)

Trace export uses a configurable sampling ratio and batches spans before export. Metric export sends data on a periodic interval. If no collector endpoint is set, both services remain inactive instead of changing local workflow behavior. (pkg/…/telemetry.go• L35-41, pkg/…/telemetry.go• L81-98, pkg/…/telemetry.go• L113-119, pkg/…/telemetry.go• L157-169)

Instrumentation carries context across service boundaries through trace carriers. Span names and custom attributes use the hatchet.run/ namespace, so related workflow activity can be grouped in the external telemetry system. (pkg/…/telemetry.go• L189-229, pkg/…/telemetry.go• L232-274)

References: pkg/…/telemetry.go• L27-33 pkg/…/telemetry.go• L35-110 pkg/…/telemetry.go• L113-186 pkg/…/telemetry.go• L189-229 pkg/…/telemetry.go• L232-274

Operational safeguards

The services favor delayed processing over blocking workflow execution. Their safeguards bound contention, storage work, and ownership so that a slow analytical operation does not become an unbounded execution failure.

Contention and retry boundaries

Status reconciliation locks the current task or workflow rows before it changes their readable state. If the target row is not ready, the update is placed back into a temporary queue with exponential delay and a retry limit. This keeps one missing or contended row from stopping later status work forever. (pkg/…/olap.sql• L978-1027, pkg/…/olap.sql• L1418-1457)

Status work is split by tenant and partition. Each batch reports whether its input remains saturated, so the controller can continue draining work without requiring one large transaction. (pkg/…/olap.go• L2140-2365, pkg/…/olap.go• L3908-3914)

Partition work uses a lease and a lock timeout. If another process owns the work or a database lock does not clear in time, the scheduled run can stop and try again later instead of holding application queries indefinitely. Concurrent controller tests cover safe repeated and contended execution. (pkg/…/olap.go• L430-447, pkg/…/olap.go• L483-610, pkg/…/olap_partition_test.go• L44-95, pkg/…/olap_partition_test.go• L183-233)

References: pkg/…/olap.sql• L978-1027 pkg/…/olap.sql• L1418-1457 pkg/…/olap.go• L2140-2365 pkg/…/olap.go• L3908-3914 pkg/…/olap.go• L430-447 pkg/…/olap.go• L483-610 pkg/…/olap_partition_test.go• L44-95 pkg/…/olap_partition_test.go• L183-233

Data volume boundaries

Run reads can include payloads only within a bounded page size. The cap applies to the rows returned by the query, not only to the requested limit, and it also applies to the total child tasks loaded for a DAG run. This prevents a history query from loading an unsafe amount of input and output data into memory. Payload cutover also bounds work by identifier ranges and can reduce its processing window when the candidate batch is too large. (pkg/…/olap.go• L50-67, pkg/…/olap.go• L912-914, pkg/…/olap.go• L1326-1328, pkg/…/olap.go• L3724-3811)

References: pkg/…/olap.go• L50-67 pkg/…/olap.go• L889-980 pkg/…/olap.go• L982-1062 pkg/…/olap.go• L1320-1345 pkg/…/olap.go• L3724-3811 pkg/…/olap_list_workflow_runs_test.go• L145-187

Partition integrity

Partition management keeps the active data window available while it creates future partitions and removes old ones. Lookup partitions also keep external identifiers unique, which preserves one trace or payload lookup target for a run. (pkg/…/olap.go• L460-610, pkg/…/olap_partition_test.go• L235-275)

References: pkg/…/olap.go• L460-610 pkg/…/olap_partition_test.go• L235-275

System relationships

OLAP and observability services sit downstream of workflow execution and upstream of most operational views. The service runtime and control plane explains their place in the platform; task and scheduling controllers explain how work changes state; and dispatcher and worker coordination explains the activity that feeds these views.

Change checklist

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

  • Keep readable status priority rules aligned across event reconciliation, direct status updates, workflow status derivation, and status-count queries.
  • Keep retry identifiers and inserted-at values aligned across lookup tables, run-to-task links, event history, payload reads, and trace lookup.
  • Keep payload cutover offsets, external block ranges, partition swaps, and payload reads compatible so offloaded payloads remain readable after restart.
  • Keep status-update backlog queries aligned with the temporary tables that the status processors consume.
  • Keep evicted-run handling aligned between active status counts and durable restore behavior.
  • Keep aggregate delta updates, compaction boundaries, raw-data fallback, and metric time windows aligned.
  • Keep partition creation, retention cleanup, and table analysis aligned with optional event and trace table settings.
  • Keep audit archive eligibility, tenant cursor ordering, object keys, completion markers, and partition removal aligned so records are not skipped or removed before upload.
  • Keep archive-store setup, file-size limits, lease renewal, and restart behavior aligned when audit retention changes.
  • Keep collector setup, signal resource labels, trace propagation, and shutdown behavior aligned when telemetry export changes.
  • Keep alert windows, the one-minute visibility lag, failed-run selection, batch limits, and tenant alert state aligned so late commits do not skip notifications.

Important failure modes

TriggerConsequenceGuard
A newer retry has the same readable status as the stored rowLater events can apply to stale retry stateAlways apply a newer retry count even when the status does not change
A completion event arrives before queueing for the same retryA completed run can regress to RUNNINGApply status priority within the newest retry
A retried attempt reports failureA task or workflow can become terminal before the retry runsRecord the event but exclude retried failures from terminal status updates
A task or workflow row cannot be locked during reconciliationThe status view can lag behind activityRequeue the update with backoff and a bounded retry count
Aggregate deltas are omitted while compaction is in progressTime-bucket metrics can undercount source activityCombine aggregate rows with delta rows until compaction catches up
Two processes run the same payload cutoverPayload indexes or partition contents can become inconsistentUse a lease and extend it during each batch
A payload cutover batch is too largeStorage work can create excess memory or I/O pressureSplit the work into ranges and reduce the window when needed
External payload data is stored without its block indexLater reads cannot find the offloaded objectRecord the identifier range and external object key in one cutover step
A partition lock does not clearScheduled partition work can block database activityUse lock timeouts and retry on a later scheduled run
A lookup partition accepts duplicate external identifiersA run can resolve to an ambiguous trace or payload recordAdd the partition-level unique external identifier constraint
An audit archive upload fails or its lease expiresThe source partition stays live and the archive run must retrySave progress per file and remove the partition only after upload completes
A process loses its lease during audit archive workA second process can resume from the saved cursor while an upload is incompleteRenew the lease for each file and use stable tenant and partition object keys
An audit partition is detached while table work holds a lockThe archive run stops without completing the partitionUse a lock timeout and retry the scheduled job after a lock conflict
Evicted work is counted only as a separate stateActive-work views can hide work that may be restoredReport evicted counts while including them in the running view
A failed run finishes near the alert query boundaryA tenant can miss a failure notification because its row is not visible yetQuery one minute behind the current time and advance from the tenant alert time
More than 1,000 failed runs finish in one alert windowThe alert batch can omit later runs from that windowKeep the bounded batch contract visible to alert scheduling and delivery
Telemetry export starts without a usable collector endpointThe service can fail during startup or lose external signalsTreat an empty endpoint as a no-op and validate configured exporter settings
Trace context is not propagated with workflow activityRelated spans appear as separate tracesInject and extract the shared trace carrier at service boundaries

Key files

FileWhy to read it
internal/…/controller.goOLAP queue routing, status workers, metric workers, alert scheduling, sampling, diagnostics, and engine span creation
pkg/…/olap.goMain contract for run views, status updates, event links, payload reads, metrics, partition work, trace lookup, failed-run selection, and audit archive setup
pkg/…/olap_audit_log_archive.goAudit partition archive flow, tenant files, restart cursor, lease ownership, and safe partition removal
internal/…/archive_audit_logs.goScheduled audit archive window and controller-level retry behavior
pkg/…/olap.sqlAnalytical rules for run history, status derivation, status metrics, failed-run selection, payload cutover, audit archive leases, and partition maintenance
pkg/…/olap.sql.goGenerated query boundary that connects the OLAP SQL contract to repository calls
internal/…/process_alerts.goTenant alert scheduling and the failed-run time window
pkg/…/olap_list_workflow_runs_test.goCoverage for workflow-run assembly, latest child output, failed-run selection, and safe payload limits in workflow-run reads
pkg/…/olap_status_update_test.goRegression coverage for retry order, replayed completions, and non-terminal retried failures
pkg/…/olap_aggregates_test.goCoverage for aggregate and delta accuracy during concurrent writes, rollbacks, deletes, and compaction
pkg/…/olap_partition_test.goCoverage for concurrent partition controllers, lock contention, creation, and lookup uniqueness
pkg/…/telemetry.goShared setup for trace and metric export, context propagation, signal labels, and collector shutdown