Designing Microservices
Q1. Monolithic vs SOA vs Microservices
Architecture | Characteristics | Pros | Cons |
---|---|---|---|
Monolithic | Single, unified application where all components (UI, business logic, database) are tightly coupled and deployed together. | - Simple to develop and test initially. - Easier deployment in early stages. - Single codebase. | - Difficult to scale individual components. - Monolithic updates can be risky. - Limited flexibility as the application grows. |
SOA (Service-Oriented Architecture) | Loosely coupled services communicating over a network (often via APIs or message queues), with each service potentially having its own database. | - Improved scalability of individual services. - Reusability of services across applications. - Better alignment with business processes. | - Increased complexity in service coordination. - Higher overhead due to network communication. - Potential data consistency issues. |
Microservices | Highly decoupled, independently deployable services, each focusing on a specific business function, with lightweight communication (e.g., REST, gRPC). | - Independent scaling and deployment. - Technology diversity (different languages/tools per service). - Resilience (failure in one service doesn’t crash the system). | - Complex distributed system management. - Increased operational overhead. - Challenges in maintaining data consistency across services. |
Q2. Advantage of using microservices?
- Scalability: Microservices can be scaled independently, optimizing resource usage for specific components.
- 可以自由使用不同的技術
Q3. Tell me your understanding of microservices?
Q4. Characteristics of microservices?
Q5. Best practices for designing microservices?
- Each service should have a single responsibility.
- Each service should have their own database.
Q6. Describe microservices architecture?
Q7. Challenges of microservices?
- Performance: Overhead of communication between services.
- Hard to track and debug
- Kibana 和 x-correlation-id去集中找log
- API expansion.
- 改一個feature要parallel 開發和deploy 多個服務
Q8. Should Databases Be Shared or Separate per Service?
- Loose Coupling:
- Each microservice owns its data and schema, allowing independent changes without affecting other services.
- Scalability:
- Each service’s database can be scaled independently based on its workload.
- Data Isolation:
- Reduces the risk of one service’s failure or bad query affecting others.
Q9. When you design the microservices, what is difficult to handle/limitation of it?
- Hard to debug
Q10. Call microservices, time out, how to deal with?
- Set Appropriate Timeout Thresholds
- Implement Retry Mechanisms
- Use Circuit Breakers
Q11. How to make decision to decide how small or how big, for split microservices
Q12. Some data share across 2 domain, how to decide primary key?
- Use UUID: globally unique identifier
- Understand the entity: e.g.
user_id
shared betweenUsers
andOrders
- Use a composite key: e.g.
user_id
andorder_id