MicroservicePatterns
MicroservicePatterns
Decomposition Patterns
Business Capability Split services
based on business domains (e.g., Order, Payment, Inventory).
Subdomain Driven Uses Domain-Driven
Design (DDD) to create microservices based on subdomains.
Strangler Fig Incrementally
migrates a monolithic system to microservices.
2. Communication Patterns
API Gateway Centralized entry
point for clients, handling authentication, routing, and aggregation.
Backend for Frontend (BFF) Custom API gateways for
different frontend clients (web, mobile).
Service Registry & Discovery Services dynamically register
themselves and discover each other (e.g., Eureka, Consul).
Circuit Breaker Prevents cascading
failures by stopping requests to failing services (e.g., Resilience4j, Hystrix).
** Circuit Breaker
Prevents cascading failures by stopping calls to a failing service.
Works like an electrical circuit breaker: If failures exceed a threshold, it
"trips" and blocks further calls.
After some time, it allows a few test calls before fully resuming.
** API Gateway
An API Gateway is a single entry point for client requests that routes them
to appropriate microservices. It acts as a reverse proxy, handling:
✅ Routing – Directs requests to the correct microservice.
✅ Security – Authenticates & authorizes users.
✅ Load Balancing – Distributes traffic efficiently.
✅ Rate Limiting – Controls request limits to prevent abuse.
✅ Logging & Monitoring – Tracks API usage & performance.
** Test-Driven Development(TDD)
Test-Driven Development (TDD) is a software development strategy that
involves writing tests before writing code.
Test-driven development (TDD) is a way of writing code that involves writing
an automated unit-level test case that fails,
then writing just enough code to make the test pass, then refactoring both
the test code and the production code, then repeating with another new test case.
Benefits of TDD
Early bug detection: TDD helps developers identify issues early in the
development process.
Improved design quality: TDD encourages developers to write clean,
maintainable, and modular code.
Faster development: TDD's fast feedback loop and automated testing
allow for faster development iterations.
Improved collaboration: TDD's shared tests help team members
communicate and collaborate more effectively.
Increased confidence: TDD helps developers be more confident in their
code.
TDD challenges
Increased Code Volume: Using TDD means writing extra code for tests
cases , which can make the overall codebase larger and more Unstructured.
False Security from Tests: Passing tests will make the developers think
the code is safer only for assuming purpose.
𝗦𝗜𝗡𝗚𝗟𝗘 𝗥𝗘𝗦𝗣𝗢𝗡𝗦𝗜𝗕𝗜𝗟𝗜𝗧𝗬 𝗣𝗥𝗜𝗡𝗖𝗜𝗣𝗟𝗘 (SRP): -> Each class should focus on a single
responsibility or task, making the system easier to maintain and modify.
𝗢𝗣𝗘𝗡/𝗖𝗟𝗢𝗦𝗘𝗗 𝗣𝗥𝗜𝗡𝗖𝗜𝗣𝗟𝗘 (OCP): -> Classes should be open for extension but closed
for modification. You can add new features without changing existing code.
𝗗𝗘𝗣𝗘𝗡𝗗𝗘𝗡𝗖𝗬 𝗜𝗡𝗩𝗘𝗥𝗦𝗜𝗢𝗡 𝗣𝗥𝗜𝗡𝗖𝗜𝗣𝗟𝗘 (DIP): -> High-level modules should not depend
on low-level modules. Both should depend on abstractions.