%% fig-alt: "Comparison of monolithic vs microservices architecture for IoT showing single application handling all functions versus separate services for device management, data ingestion, analytics, and alerting that can scale independently"
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#7F8C8D', 'fontSize': '14px'}}}%%
graph TB
subgraph mono["Monolithic (Old Way)"]
M[One Big Application<br/>Device Management +<br/>Data Ingestion +<br/>Analytics +<br/>Alerting]
end
subgraph micro["Microservices (New Way)"]
D[Device Service]
I[Ingestion Service]
A[Analytics Service]
AL[Alert Service]
end
D <--> I
I <--> A
A <--> AL
style M fill:#E67E22,stroke:#2C3E50,color:#fff
style D fill:#16A085,stroke:#2C3E50,color:#fff
style I fill:#16A085,stroke:#2C3E50,color:#fff
style A fill:#16A085,stroke:#2C3E50,color:#fff
style AL fill:#16A085,stroke:#2C3E50,color:#fff
310 SOA and Microservices Fundamentals
310.1 Learning Objectives
By the end of this chapter, you will be able to:
- Compare SOA and Microservices: Understand the evolution from Service-Oriented Architecture to microservices and when each approach is appropriate for IoT systems
- Apply Service Decomposition: Break down IoT platforms into independent, loosely coupled services using domain-driven design principles
- Identify Service Boundaries: Use the two-pizza rule and domain analysis to determine optimal service granularity
310.2 Prerequisites
Before diving into this chapter, you should be familiar with:
- Cloud Computing for IoT: Understanding cloud service models (IaaS, PaaS, SaaS) and deployment patterns provides essential context for where microservices run
- IoT Reference Architectures: Knowledge of layered IoT architectures helps understand how services map to device, gateway, and cloud tiers
- Communication and Protocol Bridging: Understanding protocol translation is essential for services that bridge device protocols to standard APIs
- MQTT Fundamentals: MQTT is the primary messaging protocol for IoT microservices communication
Microservices are like having a team of specialists where each friend does ONE job really well!
310.2.1 The Sensor Squad Adventure: The Pizza Restaurant Problem
Imagine the Sensor Squad wanted to open a pizza restaurant! At first, Sunny the Light Sensor tried to do EVERYTHING alone: take orders, make dough, add toppings, bake pizzas, AND deliver them!
Poor Sunny was exhausted and pizzas were slow. “I can only make 3 pizzas per hour doing everything myself!” Sunny complained.
Then Motion Mo had a brilliant idea: “What if we each do just ONE thing we’re really good at?”
- Sunny became the Order Taker (just takes orders, nothing else!)
- Thermo became the Oven Master (just bakes, knows exactly when pizzas are done!)
- Pressi became the Dough Maker (presses and stretches dough perfectly!)
- Droppy became the Topping Artist (adds just the right amount of cheese!)
- Signal Sam became the Delivery Driver (knows all the fastest routes!)
Now they could make 20 pizzas per hour! And when the restaurant got REALLY busy, they just added more Sunnys to take orders, without needing more of everyone else. That’s microservices!
310.2.2 Key Words for Kids
| Word | What It Means |
|---|---|
| Service | One helper that does just ONE specific job really well |
| Microservice | A tiny service that only knows how to do one thing (like ONLY taking orders) |
| API | The special language services use to talk to each other (“Hey Thermo, bake pizza #5!”) |
| Container | A special box that has everything a service needs to do its job |
310.2.3 Try This at Home!
The Restaurant Game: Play restaurant with your family! Give each person ONE job only: - One person takes orders (writes them down) - One person “cooks” (counts to 10 for each order) - One person “delivers” (brings the paper to the customer)
Time how long it takes to complete 5 orders. Now try it with one person doing ALL jobs. Which was faster? That’s why computers use microservices!
310.3 Getting Started (For Beginners)
310.3.1 What is a Service? (Simple Explanation)
Think of a service as a specialized worker in a factory:
| Traditional App | Service-Based App |
|---|---|
| One giant program does everything | Many small programs, each doing one thing |
| Like one person running a restaurant | Like a team with chef, waiter, cashier |
| Change one thing, redeploy everything | Change one service, deploy just that |
Real IoT Example:
Instead of one monolithic IoT platform:
310.3.2 SOA vs Microservices: The Evolution
Service-Oriented Architecture (SOA) came first (2000s): - Services share a common Enterprise Service Bus (ESB) - Centralized governance and contracts - Designed for enterprise integration
Microservices evolved from SOA (2010s): - Each service is fully independent - Decentralized data management - Designed for cloud-native deployment
| Aspect | SOA | Microservices |
|---|---|---|
| Communication | Enterprise Service Bus (ESB) | Lightweight APIs (REST, gRPC) |
| Data | Shared database common | Database per service |
| Size | Larger, coarse-grained | Smaller, fine-grained |
| Governance | Centralized | Decentralized |
| Deployment | Often shared servers | Independent containers |
| Best For | Enterprise integration | Cloud-native apps |
%% fig-alt: "Evolution diagram showing SOA with Enterprise Service Bus connecting services to shared database versus microservices with API gateway connecting independent services each with own database and message queue"
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#7F8C8D', 'fontSize': '14px'}}}%%
graph TB
subgraph soa["SOA Architecture"]
ESB[Enterprise Service Bus]
S1[Order Service]
S2[Inventory Service]
S3[Shipping Service]
DB[(Shared Database)]
S1 <--> ESB
S2 <--> ESB
S3 <--> ESB
ESB <--> DB
end
subgraph micro["Microservices Architecture"]
GW[API Gateway]
M1[Order Service]
M2[Inventory Service]
M3[Shipping Service]
MQ[Message Queue]
DB1[(Orders DB)]
DB2[(Inventory DB)]
DB3[(Shipping DB)]
GW --> M1
GW --> M2
GW --> M3
M1 --> DB1
M2 --> DB2
M3 --> DB3
M1 <--> MQ
M2 <--> MQ
M3 <--> MQ
end
style ESB fill:#E67E22,stroke:#2C3E50,color:#fff
style GW fill:#16A085,stroke:#2C3E50,color:#fff
style DB fill:#7F8C8D,stroke:#2C3E50,color:#fff
310.4 Service Decomposition Strategies
Breaking a system into services requires careful thought. Poor decomposition leads to a “distributed monolith” - all the complexity of microservices with none of the benefits.
310.4.1 Decomposition Approaches
1. Decompose by Business Capability
Align services with business functions:
| Business Capability | IoT Service | Responsibility |
|---|---|---|
| Device Lifecycle | Device Registry | Provisioning, updates, retirement |
| Data Collection | Telemetry Ingestion | Receive, validate, route sensor data |
| Analysis | Analytics Engine | Process, aggregate, detect patterns |
| User Notification | Alert Service | Trigger and deliver alerts |
| Billing | Usage Metering | Track consumption, generate invoices |
2. Decompose by Subdomain (Domain-Driven Design)
%% fig-alt: "Domain-driven design decomposition for IoT platform showing bounded contexts for device management, telemetry, analytics, and user management with anti-corruption layers between contexts"
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#7F8C8D', 'fontSize': '14px'}}}%%
graph TB
subgraph core["Core Domain"]
TS[Telemetry Service<br/>Core business value]
AN[Analytics Service<br/>Competitive advantage]
end
subgraph support["Supporting Domain"]
DM[Device Management<br/>Necessary but not unique]
AL[Alerting<br/>Standard patterns]
end
subgraph generic["Generic Domain"]
AUTH[Authentication<br/>Buy or use SaaS]
BILL[Billing<br/>Standard solution]
end
TS --> AN
DM --> TS
AN --> AL
AUTH --> DM
BILL --> DM
style TS fill:#16A085,stroke:#2C3E50,color:#fff
style AN fill:#16A085,stroke:#2C3E50,color:#fff
style DM fill:#E67E22,stroke:#2C3E50,color:#fff
style AL fill:#E67E22,stroke:#2C3E50,color:#fff
style AUTH fill:#7F8C8D,stroke:#2C3E50,color:#fff
style BILL fill:#7F8C8D,stroke:#2C3E50,color:#fff
Core Domain: Your competitive advantage. Build custom, invest heavily. Supporting Domain: Necessary but not unique. Build or customize. Generic Domain: Same everywhere. Buy off-the-shelf or use SaaS.
For IoT platforms, telemetry processing and analytics are typically core domains, while authentication and billing are generic.
310.4.2 Service Boundaries: The Two-Pizza Rule
Amazon’s “two-pizza rule”: If a service team can’t be fed by two pizzas, the service is too big.
Signs your service is too large: - Multiple teams work on it - Deployments require coordination - Changes frequently cause unrelated breakages - Different parts have different scaling needs
Signs your service is too small: - Excessive inter-service communication - Simple operations require multiple service calls - Shared data requires distributed transactions - Team manages 10+ services
310.5 Summary
This chapter introduced the fundamental concepts of service-oriented architectures for IoT:
- SOA vs Microservices: SOA fits enterprise integration with existing systems; microservices fit new cloud-native development
- Service Decomposition: Align with business capabilities, use DDD for domain boundaries, follow the two-pizza rule for team size
- Monolith-First: Start with a well-structured monolith for MVP; extract microservices when you hit team coordination bottlenecks or scaling limits
In one sentence: Choose your service architecture based on team size, existing systems, and scale requirements - not based on what’s trendy.
Remember this rule: For small teams (<10 developers) and moderate scale (<50K devices), a well-structured monolith ships faster and is easier to maintain than premature microservices.
310.6 What’s Next?
Continue learning about service architectures:
- SOA API Design and Service Discovery: Design resilient APIs with versioning strategies and implement dynamic service discovery
- SOA Resilience Patterns: Build fault-tolerant systems with circuit breakers, bulkheads, and retry mechanisms
- SOA Container Orchestration: Deploy and manage containerized services with Docker and Kubernetes