CASE STUDY — DIAGNOSIS

The Structural Flaw

The billing platform understood deeply enough to name its structural flaw. The internal models mirror the payment provider's models. A second provider is shimmed. Every seam leaks.

The billing platform processes millions of subscription changes, invoice finalizations, and payment attempts every month across three functional areas. It works — but it works because one payment provider is dominant. The internal data models, the event contracts, the retry logic — all of it assumes that provider's shape. When a second provider enters the picture, it takes the wrong path at every seam. This isn't a bug. It's architecture.

THE THREE AREAS
Three billing areas connected through shared mutable state
Three billing areas connected through shared mutable state

The billing platform divides into three functional areas, each with its own relationship to the payment provider. Understanding these boundaries — and where they leak — is the foundation of the diagnosis.

Area 1: Account Management

Customer creation, payment method attachment, billing profiles. The blind surface — it stores references to the provider's objects without understanding them. Spans the customer dashboard, internal API gateway, and admin panel.

Area 2: Subscription Commerce

Plan changes, proration, pricing. The most complex area — driven by a multi-stage calculation pipeline. Commits state before payment, then attempts to roll back on failure.

Area 3: Automated Billing

Invoice finalization, payment attempts, dunning, entitlement enforcement. Event-driven handlers that assume the provider's webhook contract. No single handler reads all shared data stores.

THE STRUCTURAL FLAW

The root cause isn't technical debt or missing features. It's a modeling decision made early: internal objects mirror the payment provider's objects. Subscriptions look like the provider's subscriptions. Invoices look like the provider's invoices. Payment methods carry the provider's type taxonomy. The provider isn't just a vendor — it's the schema.

Provider Model Leakage

Every internal model — subscription, invoice, payment method, customer — carries the provider's shape as its canonical form. The shared database tables model the provider's ontology. The integration packages don't encapsulate the provider — they propagate it. Domain logic speaks the provider's nouns, not billing nouns.

The Second Provider Proof

A second payment provider enters a world shaped for the first and takes the wrong path at every seam. Wrong dunning path. Wrong collection path. Not a provider-specific problem — an existence proof that the architecture can only serve one provider.

THE COUPLING TRIANGLE
Coupling cycle: A1 → A2 → A3 → A1 through different integration mechanisms
Coupling cycle: A1 → A2 → A3 → A1 through different integration mechanisms

Three areas form a directed cycle — each depends on the next through a different integration mechanism. All three reach inward to the same shared mutable state.

THE FAILURE MODES

The structural flaw produces measurable failures. These trace back to two root causes: no single component sees the full picture, and internal models mirror the provider's models.

Failure ModeRoot CauseArea
Daily rollbacksCommit-before-pay ordering — mutations persisted before payment confirmedSubscription Commerce
Bad debt from upgradesUncollectible invoices from failed rollbacks that left orphaned chargesCommerce → Billing
State disagreementsHandlers writing subsets of shared state, no component reads all storesAutomated Billing
Low invoice coverageEach handler covers one event type — minority of event paths handledAutomated Billing
Escalating support volumeCustomers hitting silent failures with no dashboard visibilityAll areas
THE COMPLETE PICTURE

The seam map above was generated by the platform's diagram tooling — the same SVG engine that renders all ten structural forms in the design system. The coupling cycle, the failure taxonomy, the area decomposition — each was authored as a YAML spec and rendered automatically. The tooling made the diagnosis legible.

The structural flaw isn't in any single component. It's in the modeling decision that shaped every component: internal objects mirror the provider's objects. Fix the models, and the failure modes disappear.