Implementing Service Decomposition Patterns

1. Decompose by Business Capability

AspectDetail
DefinitionOne service per stable business capability (Order Mgmt, Billing, Catalog)
SourceBusiness architecture / capability map
StabilityCapabilities change slowly → stable boundaries
ProsAligns with business; reduces re-orgs of code
ConsRequires clear business model

Example: Capability Map → Services

Capability               Service
---------------------    ----------------
Customer Management   →  customer-service
Product Catalog       →  catalog-service
Order Management      →  order-service
Payment Processing    →  payment-service
Shipping              →  shipping-service

2. Decompose by Subdomain

Subdomain TypeDescriptionService Strategy
CoreDifferentiates business; high investmentCustom service, top talent
SupportingNecessary but not differentiatingCustom or off-the-shelf
GenericCommon (auth, payments)Buy / use SaaS / open source

3. Decompose by Use Case

AspectDetail
DefinitionService per actor's use case (e.g., "Place Order", "Track Shipment")
InspirationUse-case driven (Jacobson), Verb-Noun
ProsMaps directly to user journeys
ConsRisk of fragmenting cohesive data; overlap with other use cases

4. Decompose by Volatility

Volatility BucketExamplesService Treatment
High VolatilityPricing rules, promotions, UX flowsIsolate so frequent changes don't risk stable code
Medium VolatilityOrder workflow, shipping optionsStandard service
Low VolatilityAuth, persistence, loggingStable platform services

5. Self-Contained Service Pattern

PropertyRequirement
Owns DataPrivate DB, no shared schema
Owns UI FragmentOptionally serves its own UI module (SCS)
No Sync CallsOperates without runtime dependence on others
Async IntegrationCommunicates via events / data replication
Failure IsolationOther services failing doesn't break it
Note: Self-Contained Systems (SCS) are a stricter form: each system includes UI, business logic, and data with minimal sync coupling.

6. Service per Team Pattern

PrincipleDetail
OwnershipOne team owns 1-N services end-to-end
No Shared ServicesTwo teams should not co-edit one service
API BoundaryCross-team interaction goes through versioned API/events
Cognitive LoadLimit per team (~5-9 services)

7. Strangler Fig Pattern

StepAction
1. IdentifyPick capability inside monolith to extract
2. FacadeInsert routing layer (API gateway / proxy)
3. BuildImplement new microservice
4. RouteGradually shift traffic from monolith to new service
5. RetireDelete old code path once 100% on new service

Strangler Migration

[Client] → [Facade/Gateway] → ┬── /orders/* → [New Order Service] (gradually 0%→100%)
                              └── /*        → [Legacy Monolith]   (gradually 100%→0%)
        

8. Anti-Corruption Layer Pattern

AspectDetail
PurposeTranslate between new domain model and legacy/external model
PlacementAdapter layer inside new service or as standalone gateway
BenefitProtects new bounded context from legacy concepts leaking in
CostExtra translation code; small latency

Example: ACL Wrapping Legacy SOAP

public class LegacyCustomerAcl {
    private final LegacyCustomerSoapClient legacy;

    public Customer getCustomer(CustomerId id) {
        LegacyCustDTO raw = legacy.fetchCust(id.value());
        return new Customer(
            new CustomerId(raw.getCustNo()),
            raw.getFName() + " " + raw.getLName(),
            Email.of(raw.getEmailAddr()));
    }
}

9. Separate Front and Backend Services

LayerResponsibility
Frontend Service (BFF)Aggregates backend APIs for a specific UI client
Backend ServiceOwns business capability and data
Why SeparateUI changes are frequent; backend capabilities are stable
Trade-offExtra hop; mitigated by colocation/caching

10. Understanding Decomposition Trade-offs

DecisionCostBenefit
More servicesNetwork ops complexityIndependent deploy/scale
Fewer servicesSlower deploys, larger blast radiusSimpler ops
Decompose by capabilityRequires domain expertiseLong-term stability
Decompose by tech layerEasy initiallyBecomes distributed monolith
Warning: Never decompose by technical tier (UI / API / DB). This guarantees a distributed monolith.