Problem statement
Design the object model and public APIs for an embeddable workflow / state-machine engine: the kernel that reads a declarative state-graph, runs many independent instances over it, and drives each one from state to state as events arrive. This is the engine a business process (an order moving order-placed -> paid -> shipped -> delivered, say) would run on, not the UI or the queue that feeds it.
Operating context. One in-process engine hosting many concurrent instances of possibly different workflows. A workflow definition is authored declaratively (states, the transitions between them, a guard condition on each transition, and the actions to run) and loaded once; the same definition object is shared by every instance that runs it. A host loop (or a message consumer) delivers events to a specific instance; the engine matches the event to an outgoing transition of the instance's current state, checks the guard, and, if it passes, runs the exit and entry actions and any transition side-effects, then advances the current state. Some transitions fire on a timer or automatically once a guard turns true rather than on an external event. An instance's runtime state must survive a process restart. The engine is single-threaded per instance; the host owns any thread pool.
Out of scope. The transport that carries events (queue, HTTP, cron), the persistence backend itself (assume a key-value store you can call — design the save/load seam, not the schema), the visual workflow editor, distributed coordination across multiple engine processes, and the authoring DSL's parser (you may reference a definition format, but do not design its grammar).
What to produce. The class hierarchy (the declarative Definition side — State, Transition, Guard, Action — versus the mutable runtime — Instance / execution context), the public API each class exposes, and the state transitions of an instance (created -> running -> waiting -> terminal). Be explicit about: how a definition is kept immutable and shared while each instance carries its own context; how one event is dispatched (transition lookup, guard evaluation, ordered exit/transition/entry actions); how side-effect hooks are invoked and what happens when one fails; how an instance's state is persisted and recovered so a restart resumes it mid-flight; and how the design stays open to new guards, actions, timed transitions, and definition versions without editing the core dispatch loop.
Requirements
This assessment is a Premium feature.
The statement above is free to read. The functional and non-functional requirements, and the graded canvas that scores your design against them, come with Premium.
Topics
- System Design LLD
- Oop Solid
- Statemachine
- Patterns State
- Extensibility