Model the Payroll Run Lifecycle as an Idempotent State Machine

Last updated: November 29, 2026

Quick Overview

Design and implement the lifecycle of a payroll run (draft, calculated, submitted, processing, paid, failed, cancelled) so that illegal transitions are rejected, edits invalidate calculations, and replayed events are harmless.

Gusto
Software Engineering Fundamentals
Software Engineer
Gusto
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Design and implement the lifecycle of a payroll run (draft, calculated, submitted, processing, paid, failed, cancelled) so that illegal transitions are rejected, edits invalidate calculations, and replayed events are harmless.

A payroll run at Gusto moves money and files taxes, so its status cannot drift because of a retried job or a double click. This checks whether you model state explicitly, keep transitions in one place and think about idempotency and time-based guards like the cancellation deadline.

What the Interviewer Expects
  • Enumerates states and allowed transitions explicitly in one table
  • Rejects illegal transitions with a clear error
  • Makes event handling idempotent with event ids
  • Encodes the funding deadline guard on cancellation
  • Keeps an audit history of transitions
  • Discusses persistence and concurrency (optimistic locking)
Key Topics to Cover
Finite state machines
Idempotency keys
Audit trail
Optimistic locking
Domain modeling
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • Two workers apply different events to the same run at once; how do you stop a lost update in the database?
  • How would you model a run that is partially paid because one employee's bank rejected the deposit?
  • Where do side effects like sending the ACH file go so they are not repeated on replay?
  • How would you migrate existing runs if you add a new state such as pending_review for risk holds?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

States: draft, calculated, submitted, processing, paid, failed, cancelled. Editing hours or earnings sends the run back to draft because totals are stale. Submission locks it. Cancellati...

High-Level Design

A transition table keyed by (state, event) is the single source of truth, which is easy to review and to render as documentation. The apply method checks a seen-events map first, then guards, then...


Submit Your Answer
Markdown supported

Related Questions