Skip to main content

Temporal Workflows for Construction: Replacing Flag-Based State Models in Harsh-Environment Operations

There is a specific kind of software failure that never throws an error. The system runs. The logs look clean. The record appears complete. But what the database says happened and what actually happened in the field are two different things — and every downstream system is now making decisions based on the wrong sequence.

That is the failure mode that drove Xgrid experts to Temporal. And if you are building software for operational environments where failure is expensive, this is the architecture conversation worth having.

Why Construction Field Operations Need Durable Workflows

Before we talk about architecture, we need to talk about context — because the technical decisions only make sense against the operational reality they were built for.

Our client is a North American construction contractor. Their crews work underground in utility tunnels, inside live industrial facilities, on high-rise frames in city centres. Before anyone touches anything on a site, there are legal and safety obligations that must be on record: the right people confirmed present, qualifications verified, hazard acknowledgements signed. Through the shift, tool assignments, work progress, and incident reports need to be captured. At the end of the day, checkout closes the record — feeding payroll, compliance, and in worst-case scenarios, incident investigations.

That is not a time-tracking problem. That is a compliance and operational record problem operating in conditions where:

  • Signal drops completely underground
  • GPS is useless inside a structure
  • Workers are gloved, moving, and not available to retry a failed request
  • A missed or corrupted record is not a bug — it is a payroll dispute or a compliance gap

Software built for office environments assumes stable internet, reliable GPS, and a user who can look at a screen whenever the app needs them. None of those assumptions hold here. The software has to absorb the messiness of the real world and still produce a record accurate enough to be trusted for payroll and regulatory audit.

What the Pre-Temporal Architecture Looked Like — and Where It Broke

The original system was built on a pattern that is reasonable, common, and brittle at scale: defensive API code on top of a flag-based state model.

Each endpoint followed the same logic:

  1. Read current state from the database
  2. Apply business logic
  3. Write updated state back

Clean in theory. The problem is that read → decide → write is not atomic. When multiple events arrive simultaneously — which happens constantly in field operations — the system races itself.

In a field environment, an offline period followed by reconnection produces a burst. Five events in two seconds, all trying to assert truth against the same record. The database handles some correctly, drops the sequencing on others, and produces a record that looks complete but reflects a sequence of events that never happened.

We had a concrete incident that illustrated the cost. A worker checked out of a site, went home, and their checkout did not fully complete due to a race condition. The system kept their shift running. The enterprise was billed for hours that were never worked.

No error was thrown. No alert fired. The system was confident. The record was wrong.

This is what we call the coherence gap — and it is the hardest failure mode to explain to someone who has not hit it, because it does not look like a failure. It looks like a complete record. The wrongness is in the sequence, and the sequence only becomes visible when you try to reconstruct what actually happened in the field.

Why Kafka Was Not the Answer

The first instinct when scoping a fix was to reach for what the team already had: Kafka.

The argument was reasonable. Put every event on a topic, let consumers handle delivery, if a consumer fails the event is still in the topic, retry from there. Kafka is a proven tool for delivery reliability. The problem is that Kafka tells you the message was delivered. It tells you nothing about the state of the business process that message was part of.

To actually solve the problem, you would still need to build:

  • A state tracking layer to know what the current status of each worker’s shift is
  • Logic to determine whether it is safe to process a given event given the current state
  • A coordination mechanism to sequence events correctly across services

You are building an orchestration layer on top of a messaging system. That is a significant amount of custom code to own, maintain, and debug — and the custom code is where the problem lives six months later when a corner case surfaces that nobody anticipated.

Why Custom Orchestration Was Not the Answer Either

The second option was manual retry logic with status flags in a coordination database. Every multi-step operation writes its state to a central table. A background job polls that table and drives operations to completion.

This pattern works. But it is expensive to build correctly. You need to account for every state transition, every failure mode, every idempotency concern. And it degrades over time — as new operations are added, as requirements change, the original model bends until it breaks.

Our estimate for building a robust version: six to eight weeks minimum, with ongoing maintenance overhead. And at the end of it, the team would still own the reliability of the solution entirely — with no guarantee that every corner case had been covered.

Neither option solved the actual problem. They both deferred it into custom code.

What Temporal Actually Is — and Why It Fits

Temporal is a durable execution engine. When you write a Temporal workflow, you are writing code that is guaranteed to run to completion — regardless of crashes, network failures, service restarts, or how long the process takes.

The workflow’s state is persisted at every step. If the worker process dies halfway through, Temporal replays the workflow from where it left off. Retry logic, timeout handling, state management, and a complete event history are provided by the runtime — not built by your team.

For the worker shift lifecycle, this was a natural fit. The workflow starts at clock-in and runs until checkout is complete and confirmed. Every meaningful event in between — signing safety documents, tool assignments, incident reports, checkout submission — is recorded in that workflow as it happens.

What this produces is something that did not exist before: one durable, ordered, inspectable record of everything that happened for that worker on that shift, as it happened.

The workflow history is the record. Not a reconstruction from five databases. Not a best-effort log correlation. The actual sequence, preserved durably, available for payroll, compliance, and audit.

The Architectural Shift in One Sentence

Before: a worker’s shift was scattered across multiple services — signature records here, timestamps there, job records somewhere else — with no single owner of the sequence.

After: one Temporal workflow owns the complete state of that shift from start to finish, and the workflow history is the authoritative record.

That shift — from scattered state to owned sequence — is what solved the coherence gap. Not because Temporal is magic, but because it gave the business process a proper home with a runtime that survives the environment it operates in.

Key Takeaway for Engineering Teams

The complexity in this system was not created by Temporal. It was already there — being paid for in support tickets, manual reconciliation, wrong payroll records, and trust erosion. Temporal gave us a place to model it honestly.

If your system has processes that have state, duration, and consequences for getting it wrong, that is the signal that durable workflow orchestration belongs in your architecture. Not because it is the fashionable choice, but because the alternative is paying the complexity tax somewhere harder to find.

Xgrid is a Temporal partner specialising in workflow orchestration for construction, industrial services, and field operations. 

Building for environments where failure is expensive? Watch how we did it — no slides, no theory, just the real architecture. https://youtu.be/gZKhpTCDPUQ

Related Articles

Related Articles