Monolith Vs MicroService
Monolith
Definition: Single massive system with a single codebase.
Advantages:
- Easy development (centralized codebase).
- Easy testing.
- Easy deployment (single executable file).
- Simple debugging.
- Good performance (can execute functions that may need multiple APIs in microservices).
Disadvantages:
- Slower development speed.
- Limited scalability.
- Lower reliability (errors in one module affect the whole application).
- Limited tech flexibility (any change in framework or language affects the entire app).
- Deployment inefficiency (small changes require full redeployment).
Microservices
Definition: Collection of small, self-contained modules based on business functionalities.
Advantages:
- Agility (small teams that can deploy frequently).
- Flexible scaling.
- Continuous deployment.
- Highly maintainable and testable.
- Independently deployable.
- Technology flexibility.
- High reliability.
Disadvantages:
- Complex management (multiple servers, teams).
- Higher infrastructure costs.
- Organizational overhead (communication and collaboration needs).
- Debugging challenges.
- Lack of standardization.
- Limited ownership of entire systems.
Strangler Fig Pattern
Purpose: Incrementally migrate functionality to new services with easy rollback if needed.
Common Setup: Reverse proxy/API gateway to handle routing with minimal impact on the existing system.
Steps:
- Identify parts of the existing system to migrate.
- Implement this functionality in a new microservice.
- Consider a "parallel run" to provide more functionality to the system.
Disadvantage: Requires interception/diversion of calls.
Branch by Abstraction Pattern
Purpose: Incremental code improvement; allows old and new code to coexist in the same version with minimal disruption.
Phases:
- Build an abstraction layer for functionality to be replaced.
- Apply the abstraction in the existing module.
- Develop new functionality in a new service (initially idle without functional flow).
- Create a service provider or wrapper to connect the new service using the abstraction.
- Redirect data flow through the new service.
- Remove the abstraction once stable.
Remote Procedure Call (RPC)
Purpose: Enables programs on different machines to call functions remotely as if they were local.
gRPC:
- Opensource RPC framework built on HTTP/2 and Protocol Buffers (protobuf) as IDL (Interface Definition Language).
- Uses HTTP/2 for efficient, concurrent data streaming with multiple messages over a single connection.
- gRPC is ideal for microservice communication, not typically for frontendbackend as it relies on lowerlevel network access.
Webhooks
Definition: A mechanism for apps to communicate via HTTP POST requests when specific events occur.
3Step Process:
- Setup: Receiver provides a unique URL for data reception.
- Event Occurrence: Triggered by specific changes.
- Execution: HTTP POST request sent to the webhook URL.
Examples:
- CI/CD systems automatically triggering builds or deployments when code changes.
- Payment processing systems updating order status and triggering actions.
- Sending automated reminders based on specific actions.