LLD Guide · Module 2: Problem prep · Lesson 02.12

Prep: Deployment Pipeline Engine

Ordered stages, one active deployment per pipeline, rollback and cancel, and a history that stays in order.

By Cruscible Engineering · Published

Five people press "deploy" on the same pipeline at once. One deployment starts; the other four get a clear "already running". Everything else in this problem is a state machine.

This lesson prepares you for Build a Deployment Pipeline Engine. It doesn't solve it.

1. What the deployment pipeline contract asks for

A pipeline is a name and an ordered list of stages. A deployment of a version starts at the first stage and advances one stage at a time until it completes, or is rolled back or cancelled. A pipeline runs at most one deployment at a time. Everything is persisted (Postgres and Redis are recommended; you may use either or both).

MethodReturns / does
createPipeline(name, stages)creates the pipeline, or overwrites one with the same name
triggerDeployment(pipeline, version)a new deployment id; throws IllegalArgumentException for an unknown pipeline, IllegalStateException if one is already running
getDeploymentStatus(id)id, pipelineName, version, currentStage, status, startedAt, completedAt; null if unknown
advanceStage(id)true and the next stage, or COMPLETED after the last one; false unless IN_PROGRESS
rollback(id)true and ROLLED_BACK; false unless IN_PROGRESS
cancelDeployment(id)true and CANCELLED; false once the deployment has finished
getHistory(pipeline, limit)up to limit deployments, most recent first

Figure: One pipeline, four stages: a deployment that completes, one rolled back, and a second trigger

2. Lessons to read before the deployment pipeline

3. Deployment pipeline design decisions to make first

  1. Does a new deployment start PENDING or IN_PROGRESS? The lifecycle lists PENDING, but read the example walkthrough: what does the status show right after triggerDeployment?
  2. What makes "at most one active" one step? Five threads trigger the same pipeline at once: exactly one returns an id and four get IllegalStateException. Where does the claim live, and what makes taking it atomic?
  3. When is the claim released? Completing, rolling back and cancelling all end a deployment. Missing one of the three blocks the pipeline forever.
  4. What is currentStage after the end? The contract says it's the last stage reached.
  5. What orders the history? Deployments triggered in the same millisecond have the same startedAt. What still tells you which came first?
  6. What does overwriting a pipeline do? createPipeline on an existing name replaces its stages. Decide what happens to its history and to a deployment already running.
  7. If you use both stores, which one is the truth? Two copies of a deployment's state have to agree after every call.

4. Deployment pipeline pitfalls

⚠️ Trap: the exception types are part of the contract. An unknown pipeline is IllegalArgumentException, a busy one is IllegalStateException. A different exception from a busy pipeline is counted as a wrong answer.

⚠️ Trap: checking "is anything running?" and then inserting a deployment in a second step lets two triggers both start.

⚠️ Trap: advanceStage and rollback return false unless the deployment is IN_PROGRESS, but cancelDeployment returns false only once it has finished.

⚠️ Trap: completedAt is null while a deployment is running, and set by all three ways it can end.

Before you submit

Further reading

After you've tried it

Submit first. The full walkthrough of one solution: Building a Deployment Pipeline Engine with Rollback Support.

Open the problem