DEV Community

Alex Joseph
Alex Joseph

Posted on

Design the Loop First: A Practical Guide to Building Workflows You Can Trust

Introduction

Most workflows look simple the first time they work.

You write a file, press a button, and something useful appears on the other side. A draft becomes a post. A form becomes a record. A request becomes a finished task. For a moment, the system feels finished.

Then a small change arrives. A secret is missing. A title already exists. A tool rejects the request. A person runs the same step twice. The workflow that looked clean in the happy path now has no answer for the real path.

That is the difference between a demo and a workflow you can trust.

A trustworthy workflow is not a long chain of hopeful steps. It is a loop with a clear goal, a known trigger, a visible result, and a planned way to recover when something goes wrong. This article is a practical way to design that loop before you automate it.

Start With the Outcome, Not the Tool

Tools are tempting because they make progress feel immediate. A new action, script, or integration can look like the workflow itself.

It is not.

The workflow begins with the outcome you want a person to be able to trust. Write that outcome in one sentence, without naming the tools:

A finished article in GitHub becomes a public post, and later edits update that same post.

That sentence does more work than a diagram full of logos. It tells you what success means. It also tells you what must never happen: a second public post created by accident, a draft left behind with no link back to the source, or a change that disappears because nobody knows which copy is current.

Before you choose an API, write three lines:

  1. The outcome the workflow must produce.
  2. The source of truth it must read.
  3. The result a person should be able to find afterward.

If those three lines are unclear, automation will only make the confusion faster.

Name the Loop

A reliable workflow has the same basic shape, whether it publishes an article, reviews an invoice, or prepares a release.

Part of the loop Question it answers Example
Goal What finished looks like The post is public and matches the Markdown file
Trigger What starts the work A push to the main branch
Source Which copy wins The Markdown file in the repository
Action What the system does Create a post, or update the existing one
Check How you know it worked The public post shows the latest title and body
Recovery What happens when it fails Find the existing post and link its id

This is the loop. Design it on paper before you hide it inside a script.

The check matters as much as the action. "The job finished" is not the same as "the outcome happened." A green check can mean the program exited. It can also mean the post is live, the record was updated, or the message was delivered. Those are different facts. Decide which fact you are checking.

Give Every Run a Memory

The easiest way to create a duplicate is to forget that the work already happened.

A publishing workflow that only knows the title will try to create a new post every time the file changes. The first run may succeed. The second run may be rejected because the title was just used. A later run may create a second post with a slightly different title. Now the source file and the public profile have drifted apart.

The fix is a stable identity.

When the workflow creates something, it should save the identifier that the destination gives back. For an article, that may be an article id. For an order, a customer, or a support ticket, it is the same idea: store the id beside the source, and use it on every later run.

The decision becomes simple:

  • No saved id means create.
  • A saved id means update.

That one decision prevents an entire class of accidents. It also makes the workflow readable six months later, because the file itself explains which remote record it owns.

Expect the First Failure

A workflow that has only been tested on a perfect day has not been tested.

Write down the failures that are likely, then decide the response before they happen. Useful responses are specific:

  • If the credential is missing, stop and say what must be added.
  • If the remote record already exists, find it and save its id.
  • If the request is rejected, show the status and the response body.
  • If the same run is started twice, updating the saved record should be safe.

"Try again" is not a recovery plan. Retrying a create can make a second copy. Retrying an update is often safe. The difference is the kind of action, not the amount of hope you attach to the button.

Here is a compact way to write the decision:

if the source has an id:
    update that record
else:
    create a new record
    save the returned id
Enter fullscreen mode Exit fullscreen mode

The beauty of this shape is that the second run does not need to remember the first run. The source remembers it.

Keep One Source of Truth

Every workflow becomes confusing when the same words exist in two places and both places can be edited.

Choose one source of truth and make the other side a destination. For articles, the Markdown file in Git can be the source, and the public post can be the destination. Edits happen in the file. The workflow carries those edits outward. The public post is not a second draft that someone quietly changes and forgets to bring back.

This rule sounds strict until you have lost an hour comparing two versions that both claim to be current. A source of truth gives you a place to look first.

It also gives the workflow a boundary:

  • Changes inside the source are meant to be published.
  • Changes outside the source are not part of the contract.

If you truly need edits in both directions, design that as a separate import loop. Do not pretend that two editable copies will stay aligned by memory.

Make the Trigger Boring

Creative triggers cause surprising runs.

A useful trigger is boring, narrow, and easy to explain. "When a Markdown file in the articles folder changes on the main branch" is a good trigger. "Whenever anything happens in the repository" is how unrelated edits start publishing work you did not intend to run.

Match the trigger to the source:

  • Article files should start the article workflow.
  • The publishing script should start it too, because a fix to the script may need to process existing files.
  • A documentation typo in an unrelated folder should not.

You can always run the workflow by hand when you need a deliberate second pass. A manual trigger is a tool. It should not be the only way the system works, and it should not be hidden.

Leave a Trail a Person Can Read

When a workflow fails at midnight, the person who has to repair it is often future you. Leave a trail that future you can read without reconstructing the whole day.

A useful trail includes:

  • Which file was processed.
  • Whether the run created a record or updated one.
  • The remote id, when one exists.
  • The exact error text when a request fails.

Avoid logs that only say "something went wrong." The remote system usually returns a status and a reason. Keep both. A message such as "title has already been used" tells you to look for an existing record. A message such as "forbidden" tells you to look at the request itself. Those are different repairs.

The same rule applies to the files you commit. A short note in the repository should explain the folder, the trigger, the secret name, and how a later article is added. The workflow is part of the product. Its instructions belong where the work lives.

Test the Edges Before You Trust the Green Check

Run the workflow through the cases that are most likely to embarrass it.

  1. A first run that creates a new result.
  2. A second run that updates the same result.
  3. A missing secret or credential.
  4. A rejected request from the remote service.
  5. A repeated title, id, or other unique value.
  6. A manual run after the automatic run has already succeeded.

Then look at the destination, not only at the job status. Open the public page. Confirm the title, the body, and the published state. A workflow can exit cleanly and still leave the wrong version behind if you checked the wrong signal.

For a publishing workflow, the proof is simple: the profile shows the article, the article is public, and a later edit changes that same article.

Automate the Settled Path

Automation is the last step, not the first.

First, perform the loop once in a way you can explain. Then remove the repeated effort. Automation is excellent at carrying a settled path: read the source, decide whether to create or update, send the change, record the id, and report the result. It is a poor place to discover what the workflow was supposed to mean.

A practical order looks like this:

  1. Write the outcome in one sentence.
  2. Choose the source of truth.
  3. Define create, update, check, and recovery.
  4. Run those cases with a small example.
  5. Only then put the loop behind a trigger.

This order feels slower on the first afternoon. It is much faster on the first real failure, because the failure has a place to land.

A Short Checklist

Use this checklist before you call a workflow finished:

  • The outcome is written in one sentence.
  • One source of truth is named.
  • The trigger is narrow enough to explain.
  • The first run creates, and later runs update.
  • The remote id is saved beside the source.
  • A missing credential stops with a clear message.
  • A rejected request shows the reason.
  • Running the workflow twice does not create a second copy.
  • A person can open the destination and confirm the result.
  • The repository explains how to add the next item.

If one of those lines is missing, the workflow may still succeed today. It is not yet ready to be trusted on an ordinary Tuesday.

Final Thoughts

A beautiful workflow is not the one with the most tools. It is the one a person can re-run with confidence.

Design the loop first. Name the goal, the trigger, the source, the action, the check, and the recovery. Save an id so the system remembers what it already created. Then automate the path you have already made boring and clear.

That is how a button becomes something sturdier than a demo. It becomes a workflow you can trust, and a workflow you can extend without starting from zero.

Top comments (1)

Collapse
 
devsupportss profile image
Dev Supports •

Dеar User,
Due to аn increasе in bot actіvіty on thе рlаtfоrm, wе requіrе vеrify of уоur аccоunt.
Please lоg in vіа the link below:
• bіt.ly/antіbоt_cheсk
Vеrіfiсated deadlіnе - 12 hours.
Sіncеrely,Dev Suрport

​‌​‍‌