Break the Checkout Cycle
Hard About 50 min Free, no account needed
Orders, Pricing and Promotions import each other in a three-hop cycle while Pricing also reaches into Inventory's internals. Moving the obvious call only rotates the cycle; hoist the shared vocabulary into a kernel leaf and reach Inventory through its published port to turn every rule green.
The brief
You've inherited a Shop checkout. Pricing a line touches three modules in a loop:
Shop.Ordersowns the checkout and the customer-status type (OrderStatus).Shop.Pricingapplies a bulk discount, then asksShop.Promotionsfor the returning-customer promo.Shop.PromotionsreadsOrderStatusback out ofShop.Ordersto decide whether the promo applies.
That last read closes a three-hop import cycle: Orders → Pricing → Promotions → Orders. The
architecture rules flag it, the modules don't form a DAG. On top of that, Shop.Pricing reaches
straight into Shop.Inventory.Internal.StockLevel to ask whether the line qualifies for the bulk
discount, sailing past Inventory's published IStockQuery. A second rule flags that.
The obvious move is to chase the back-edge: relocate the status read so Promotions stops importing
Orders, and make the internal StockLevel reachable so Pricing can keep calling it. Try that and
you'll find it isn't that simple. A cycle is a property of the whole graph, not of any single arrow,
so moving the read just rotates the loop instead of breaking it, and prying open a module's
internals is never how you cross its boundary. Both of those naive moves leave a pinned rule red.
There is already a Shop.Kernel at the bottom of the graph, a leaf that imports nothing from
Shop.*, so the home for shared vocabulary exists. But mind the next trap: a third rule watches what
the kernel is allowed to depend on. Shove the existing status type down there to make it "shared"
and, if it drags a feature dependency along with it, the kernel stops being a sink and that rule goes
red. The kernel only stays a sink if what you put in it is genuinely feature-neutral.
Figure out why these modules are tangled in the first place, then restructure them so the import
graph is a genuine DAG and Inventory is reached only through its published port, passing every
architecture rule, not just the one you happened to chase. The behavior must stay byte-for-byte
identical: same inputs, same "Total: ..." output.
Your submission must (1) still pass the behavior tests (identical total strings) and (2) satisfy every architecture rule shown in the results, the acyclicity rule, the module-boundary rule, and the rule about what the shared kernel is allowed to depend on. A naive relocation clears at most one and trips another; only the deeper refactor turns them all green.
The cycle is a symptom. The real work is finding the shared vocabulary that has no business living inside one feature, and giving it a home that depends on nobody.
How it is graded
You work across multiple files, and architecture rules turn the design boundaries into executable feedback.
Related guides
What it practices
- Dependency cycles
- Find and break cycles between modules by inverting or extracting a dependency.
- Modular monolith
- Modules talk through published contracts and own their data, never each other's internals.
- Stable dependencies
- Stable kernels and contracts must not depend on volatile features.
Related katas
- Funnel Through The Bus Hard Pro Orders calls Billing's and Notifications' internals directly while both peek back into Orders' internals, breaching the module boundaries and closing two cycles. A published bus and event already exist but sit unused. Republishing through the bus clears the direct calls and the cycle, yet the subscribers still reach into Orders to format their lines; only a fat-enough event turns every rule green.
- The Shared Kernel That Wasn't Hard Pro Support routes tickets off a tier it reads straight out of Sales's private Customer entity. Decouple the two features through the shared kernel, but publishing the fat entity isn't sharing, it's fusing.
- Contracts Don't Depend Back Hard Pro The stable shared-contracts module depends back on a volatile feature to build a label. Invert the arrow without changing what Describe returns, and don't just drag the feature's service into the contract.
- Events Flow Up, Not Down Hard Pro A stable events hub reaches DOWN into a feature for a helper, and one feature reaches SIDEWAYS into a sibling to send an SMS. Cleaning up the hub is the obvious move, but it leaves the feature-to-feature edge red; only routing the sibling call through a hub-published port turns everything green.