Understanding Microservices Fundamentals

1. Understanding Microservices Architecture

AspectDescriptionImplication
DefinitionArchitectural style where applications are composed of small, autonomous servicesEach service owns a single business capability
Service SizeSmall enough to be owned by one team (2-pizza rule)Typically 100-10K LOC per service
CommunicationNetwork-based via APIs (REST, gRPC, messaging)Higher latency than in-process calls
Data StorageEach service owns its database (Database per Service)No shared schemas between services
DeploymentIndependently deployable artifacts (containers, serverless)Enables continuous delivery per service
Technology StackPolyglot — each service can use optimal techJava, Go, Node.js, Python coexist

High-Level Architecture

   [Client] → [API Gateway] → ┬── [Order Service] ── [Order DB]
                              ├── [Payment Service] ── [Payment DB]
                              ├── [Inventory Service] ── [Inventory DB]
                              └── [Notification Svc] ── [Notification DB]
                                         ↕
                              [Message Broker (Kafka)]
        

2. Understanding Microservices Characteristics

CharacteristicMeaningBenefit
AutonomyIndependently developed, deployed, scaledTeam velocity, fault isolation
Decentralized GovernanceNo central architecture committee dictates techTech diversity, faster innovation
Decentralized DataEach service owns its persistenceSchema evolution without coordination
Smart Endpoints, Dumb PipesLogic in services; messaging is plain transportAvoids ESB-style complexity
Design for FailureNetwork/services WILL fail; build resilience inHigher availability
Evolutionary DesignServices replaced/refactored independentlyLower change cost
Infrastructure AutomationCI/CD, IaC, container orchestrationManageable at scale

3. Understanding Service Boundaries

HeuristicRuleAnti-Pattern
Business CapabilityOne service per stable business functionSplitting by technical layer (UI/DB)
Data CohesionData that changes together lives togetherJoining across service DBs
Change FrequencyGroup code that changes togetherCo-deploying unrelated services
Team TopologyOne team per service (Conway's Law)Multiple teams editing same service
Transactional BoundaryOne ACID transaction = one serviceDistributed transactions across services

Example: E-commerce Service Boundaries

Catalog Service        → Products, categories, search
Order Service          → Cart, checkout, order lifecycle
Payment Service        → Payment processing, refunds
Inventory Service      → Stock levels, reservations
Shipping Service       → Carriers, tracking, delivery
Customer Service       → Profiles, addresses, preferences
Notification Service   → Email, SMS, push notifications

4. Understanding Service Independence

DimensionIndependentCoupled (Bad)
BuildSeparate repo/pipeline per serviceMonorepo with single build
DeployDeploy v2 of A without redeploying BLockstep releases
ScaleScale A to 100 replicas, B stays at 2Scale entire app together
DatabaseEach service owns DB schemaShared tables across services
RuntimeFailure of A degrades but doesn't crash BCascading failures
Warning: If you cannot deploy a service independently, it's not a microservice — it's a distributed monolith.

5. Understanding Single Responsibility Principle

QuestionAnswer Indicates
"Why would this service change?"If multiple unrelated reasons → split it
"Who owns the requirements?"Multiple stakeholders → split by stakeholder
"What is its single business capability?"If you can't state it in one sentence, refactor
"Does it have one source of truth?"Yes → good cohesion; No → too broad

6. Understanding Microservices vs Monolith

DimensionMonolithMicroservices
DeploymentSingle artifact, all-or-nothingIndependent per service
ScalingScale entire appScale per service
Tech StackSingle stackPolyglot
DataSingle shared DBDatabase per service
Team CoordinationHigh (shared code)Low (autonomous teams)
Operational ComplexityLowHigh (network, observability)
Initial VelocityFastSlow (infrastructure setup)
Long-term VelocitySlows with sizeSustains with size
Best ForSmall teams, early productLarge orgs, mature product
Note: Start with a well-structured modular monolith. Extract microservices when team size, change frequency, or scaling needs justify the complexity.

7. Understanding Distributed Systems Challenges

FallacyRealityMitigation
Network is reliablePackets drop, partitions occurRetries, circuit breakers
Latency is zeroRTT can spike to secondsTimeouts, async, batching
Bandwidth is infiniteThrottling, congestion happenCompression, pagination
Network is secureThreats inside and outmTLS, zero-trust, encryption
Topology never changesInstances scale, IPs changeService discovery
One administratorMany teams, many cloudsFederated governance
Transport cost is zeroSerialization, marshalling cost CPUEfficient formats (Protobuf)
Network is homogeneousMix of clouds, regions, protocolsAdapters, gateways

8. Understanding Service Granularity

GranularityIndicatorsRisk
Too Coarse (Mega Service)>3 teams, multiple capabilities, slow deployBecomes mini-monolith
Right-SizedOne team, one capability, focused API
Too Fine (Nanoservice)Trivial logic, high inter-service chatterNetwork overhead, ops burden
Note: Optimize for cognitive load and deploy independence, not for "smallest possible" services.

9. Understanding Service Ownership

AspectOwning Team Responsibility
CodeRepo, PRs, code reviews, tech choices
Build & DeployCI/CD pipelines, release cadence
RuntimeSLOs, on-call, incident response
DataSchema, migrations, retention
API ContractVersioning, deprecation, docs
CostCloud spend, optimization

"You Build It, You Run It"

  • Devs own production operation, not a separate ops team
  • Reduces feedback loop between defects and fixes
  • Drives quality through accountability

10. Understanding Conway's Law

ConceptDescription
Conway's Law"Organizations design systems that mirror their communication structure"
Inverse Conway ManeuverRestructure teams to drive desired architecture
Team TopologiesStream-aligned, Platform, Enabling, Complicated-subsystem teams
Cognitive LoadEach team owns services within its mental capacity (~5-9 services)
Communication CostCross-team dependencies → API contracts; intra-team → code