Microservices
Small Autonomous Services that work together, modeled around business domain
- Subset of Service Oriented Architecture(SOA)
- Allow use of multiple DB & Tech Stacks for differeent features
Principal of MicroServices
1. Domain Driven Design
- Services Modelled around Business Domain
- Service decomose by business fomain
- Slice vertically
- Team expert in perticular domain
2. Automation CI/CD
- Create a platform for deploying service.
- Automate testing & deployment process for scaling with confidence.
- Setting up a Process help scaling service easily.
- Build->Test->UAT->Performance->Prod
3. Abstraction
- Hide Implementation Detail from other service
- Hide Database and allow service to communicate over service to access DB
- Abstarction allow changing in Tables easier.
- Easier to expose Info what is hidden than hide Info what is Shown
4. Independently Deployability
- Avoid Release Train
- Must not have aneed redeploy entire System if a service changes
- Add test for dependent service using Test cases as Pact to give confidence
- Co Exist End Point-Beta API release to give consumer time to upgrade.
5. Distributed/ Decentralized Power Across Team
- Give power to team
- Team must be autonomus
- A man with power slow down the process
6. Consumer First
- Make life easy for Developer
- Good Documentation
- Provide Swagger JSON
7. Isolate Failure
- Reduce Impact of failure of Service failure
- Reduce Cascading failure
8. Highly Observable
- Logs to monitor failure
- Error Logs & Failure
- Latency of calls between service
- ID to trace service flow
Migration to MicroService
Monolith Types
-
Single Process Monolith
- All code in a Single process
- All data in single DB
-
Modular Monolith
- Code is broken into modules.
- Teams work on split modules
- All Modules are packaged together into a single process
- All data in single DB
-
3rd Party Monolith
- Limited to no abaility to change core system
- Might have access to storage & API
-
Distributed Monolith
- Process communicate over process
- Complex release System
- Downside of both distributed system &
- Large scoped deployment lerage
- High cost of change & risk
- Release train to abort before release
Issue with monolith
- Scalability
CAP Theory
- In a Partion we have to tradeoff Consistancy over Availability
Compariosn to MicroService
| monolith | Microservice |
|---|---|
| Simplicity | Incremental Partial Development |
| Consistancy of DBMS | High Availability of Services |
| Inter module refactoring b/n module boundry | Force Preserve Modularity all the time |
| Fix Tech Stack and hard to change | Flexibility of Multiple platforms Tech stack/dbms/platform |
Decomposition
Incremental Upgrade
- Extract a process to Micro Service
- Increamental extract & refactor feature/process
- Wrap new functionality around old functionality
Routing
- Find issue with Network beforehand and add HTTP Proxy
- HTTP Proxy divert call to Monolith and Side Service
Branch by Abstraction
- Add abstraction around functionality
- It Give swap point for changing feature
- Start work on a new service
- Switch Service
- Clean Up
Parallel Run
- Call current service & new service
- Varify new service output & check if it behave same as Existing implementation
Accessing Data
- MS need to access same data
- Direct access cause Coupling Problem
- Go through Monolith to access DB in this case
- Dependency can be inverted in case Monolith need data from Monolith
CAP Theory
- In a Partion we have to tradeoff Consistancy over Availability
Security
Prevention-> Detection-> Response- >Recovery
- Attack Tree
- Brainstorm ways attack can happen and try to prevent them
- Find possible point of attack & Possibility of cracking
- HTTPS
- Server gurantees
- Payload not manipulated
- Client not guarantee
- Make sure Certificate is Secure and Authentic
- Client side Certificate
- Client guarantees
- Add Authentication (OAuth, FormAuth)
- User access management
- Confused Deputy
- Whoever asking a data is authenticated
- Token validation
- Security Problem in Docker Image
- Check if image is up to date
- Check if docker image have vulnaribility
- Patch the tech stack
