Microservice Flashcards

1
Q

Question:
What are the key principles to consider when defining microservice boundaries?

A

Answer:
1. Information Hiding:
- Hide internal implementation details and expose only necessary interfaces to ensure changes within a service do not affect others.

  1. Cohesion:
    • Ensure high cohesion by focusing each service on a single business capability or domain.
  2. Coupling:
    • Maintain low coupling by minimizing dependencies between services to allow for independent evolution.
  3. Domain-Driven Design (DDD):
    • Align microservice boundaries with business domains using concepts like bounded contexts and
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Question:
Can you explain the concept of information hiding in the context of microservices?

.

Ready for the next question?

A

Answer:
Information Hiding: In microservices, information hiding means each service encapsulates its internal details and exposes only the necessary interfaces for interaction, promoting loose coupling and independent deployability.

Example - Order Service in a Bookstore:

Public API:
- createOrder
- updateOrder
- deleteOrder
- getListOfPreviousOrders

Internal Processes Hidden:
- Internal order creation, updating, and deletion processes.
- Order data management (e.g., soft delete, data storage details).
- Handling other users’ orders and internal data persistence logic.

Benefits:
1. Loose Coupling: Independent changes without affecting other services.
2. Security: Protects sensitive information and processes.
3. Simplified Interfaces: Easier to understand and use the service.
4. Flexibility: Allows internal implementation changes without API changes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the types of coupling that can occur between microservices, and how can they be managed?

.

A

1. Domain Coupling:
- Example: Order Service and Inventory Service both need to understand the “order” concept. Changes in the “order” definition require updates in both services.
- Problem: Coordinated updates across services, hindering independent deployment.

2. Pass-Through Coupling:
- Example: Payment Service passes order requests to Shipping Service without processing them.
- Problem: Dependency chain and single point of failure. Changes in order request format affect all services in the chain.

3. Common Coupling:
- Example: Multiple services (User, Order, Payment) access a shared configuration file for database connection strings and service endpoints.
- Problem: Changes to shared configuration can cause widespread issues and make debugging difficult.

4. Content Coupling:
- Example: Inventory Service directly accesses Order Service’s database to retrieve order details.
- Problem: Direct database access creates strong dependencies. Schema changes in Order Service can break Inventory Service

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Question:
Can not using domain events contribute to creating a “big ball of mud” architecture in microservices? If so, how?

A

Answer:
Yes, not using domain events can contribute to creating a “big ball of mud” architecture. Here’s how:

Problems Without Domain Events:

Direct Synchronous Calls:

Leads to tight coupling between services.
Changes in one service can break others.
Reduces system resilience to failures.
Shared Databases:

Results in a tightly coupled, monolithic data model.
Schema changes affect multiple services.
Difficult to manage and evolve the database.
Inconsistent State:

Hard to maintain consistent state across services.
Each service may have a partial view of the data.
Leads to outdated or incorrect data.
Benefits of Using Domain Events:

Asynchronous Communication:

Decouples services by allowing independent reactions to events.
Services emit and listen for events without direct calls.
Event-Driven Architecture:

Uses event brokers to handle publishing and subscribing of events.
Further decouples services and ensures loose coupling.
Resilience and Scalability:

Enables asynchronous processing, improving resilience.
Allows services to scale independently.
Consistent State Management:

Keeps state consistent across services.
Ensures all services have a real-time, consistent view of data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does domain-driven design (DDD) help in modeling microservices?

A

Answer:
1. Understanding the Domain:

Approach: Deep understanding of the business domain.
Benefit: Ensures each microservice corresponds to a specific area of business functionality.
2. Ubiquitous Language:

Approach: Common language shared by developers and domain experts.
Benefit: Reduces miscommunication and errors, ensuring consistent understanding.
3. Bounded Contexts:

Approach: Defines boundaries within which a particular model is applicable.
Benefit: Ensures each service has a well-defined scope, reducing ambiguity and overlap.
4. Aggregates:

Approach: Clusters of domain objects treated as a single unit.
Benefit: Maintains data consistency within a microservice, promoting encapsulation.
5. Domain Events:

Approach: Captures significant occurrences within the domain.
Benefit: Enables decoupled communication between services, supporting asynchronous interactions.
6. Strategic Design:

Approach: Distinguishes between core, supporting, and generic subdomains.
Benefit: Prioritizes efforts on core domains, ensuring microservices deliver the most business value.
Example:

Core Domain: Identify key areas like order processing, payment handling.
Ubiquitous Language: Use consistent terms like “Order,” “Payment,” “Inventory.”
Bounded Contexts: Define contexts like Order Management, Payment Processing.
Aggregates: Model aggregates like an Order with Order Items.
Domain Events: Use events like OrderPlaced, PaymentProcessed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a key principle to consider when defining microservice boundaries?
a) Information hiding
b) Code sharing
c) Centralized databases
d) Monolithic structure

A

Question 1:
What is a key principle to consider when defining microservice boundaries?
a) Information hiding
b) Code sharing
c) Centralized databases
d) Monolithic structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which of the following scenarios demonstrates poor use of bounded contexts in microservices?
a) The Order Service handles all order-related data and processes, while the Inventory Service manages stock levels independently.
b) The Payment Service manages payment transactions, but also directly accesses and modifies customer details stored in the Customer Service.
c) The Shipping Service processes shipping requests and communicates with the Order Service through well-defined APIs.
d) The Recommendation Service uses data from the Order Service and Inventory Service but only through their public APIs.

A

Answer: b) The Payment Service manages payment transactions, but also directly accesses and modifies customer details stored in the Customer Service.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which type of coupling occurs when multiple services share global data or configurations?
a) Domain coupling
b) Pass-through coupling
c) Common coupling
d) Content coupling

A

Answer: c) Common coupling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does Domain-Driven Design (DDD) help in modeling microservices?
a) By using a monolithic approach
b) By aligning microservices with business domains
c) By ensuring all services use the same database
d) By ignoring business processes

A

Answer: b) By aligning microservices with business domains

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a bounded context in DDD?
a) A centralized database
b) A boundary within which a particular model is defined and applicable
c) A type of coupling
d) An external API

A

Answer: b) A boundary within which a particular model is defined and applicable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which technique involves identifying domain events, commands, and aggregates to model microservices?
a) Code refactoring
b) Event storming
c) Database normalization
d) Load testing

A

Answer: b) Event storming

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which criterion is NOT typically used to define microservice boundaries?
a) Volatility
b) Scalability
c) Data ownership
d) Single-threaded execution

A

Answer: d) Single-threaded execution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Question 8:
How does using domain events benefit microservices?
a) By increasing coupling between services
b) By decoupling services and supporting asynchronous communication
c) By centralizing all data processing
d) By making services more dependent on each other

A

Answer: b) By decoupling services and supporting asynchronous communication

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the main benefit of defining microservice boundaries based on team structure and responsibilities?
a) Clear ownership and accountability
b) Increased system complexity
c) Shared data models
d) Uniform technology stack

A

Answer: a) Clear ownership and accountability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which of the following is an alternative criterion to business domain boundaries when defining microservice boundaries?
a) Performance and latency
b) Centralized logging
c) Single point of failure
d) Direct database access

A

Answer: a) Performance and latency

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which type of coupling involves one service passing data it does not process to another service?
a) Domain coupling
b) Pass-through coupling
c) Common coupling
d) Content coupling

A

Answer: b) Pass-through coupling

17
Q

What does DDD emphasize for ensuring clear communication and understanding?
a) Centralized control
b) Ubiquitous language
c) Database sharing
d) Monolithic architecture

A

Answer: b) Ubiquitous language

18
Q

Why is it important to avoid direct database access between microservices?
a) It simplifies code sharing.
b) It allows for independent schema changes and better encapsulation.
c) It enhances database performance.
d) It reduces the number of services needed.

A

Answer: b) It allows for independent schema changes and better encapsulation.

19
Q

Question 1:
What are the main differences between in-process and inter-process communication in microservices?

a) Performance and Network Usage
b) Data Serialization and Network Usage
c) Performance, Data Serialization, and Network Usage
d) Performance and Data Storage

A

Answer: c) Performance, Data Serialization, and Network Usage

20
Q

Question 2:
What are the advantages of synchronous blocking communication in microservices?

a) Loose Coupling, Immediate Feedback, Easier Debugging
b) Simplicity, Immediate Feedback, Easier Debugging
c) Complexity, Scalability, Resource Consumption
d) Flexibility, Loose Coupling, Scalability

A

Answer: b) Simplicity, Immediate Feedback, Easier Debugging

21
Q

Question 3:
What are the disadvantages of synchronous blocking communication in microservices?

a) Tight Coupling, Scalability Issues, Increased Latency, Resource Consumption
b) Loose Coupling, Scalability Issues, Increased Latency, Resource Efficiency
c) Tight Coupling, Immediate Feedback, Increased Latency, Resource Consumption
d) Loose Coupling, Immediate Feedback, Increased Latency, Resource Consumption

A

Answer: a) Tight Coupling, Scalability Issues, Increased Latency, Resource Consumption

22
Q

Question 4:
What are the advantages and disadvantages of asynchronous nonblocking communication in microservices?

a) Resource Efficiency, Scalability, Reduced Latency, Complex Error Handling
b) Resource Efficiency, Scalability, Increased Latency, Complex Error Handling
c) Immediate Feedback, Simplicity, Reduced Latency, Complex Error Handling
d) Resource Efficiency, Scalability, Immediate Feedback, Complex Error Handling

A

Answer: a) Resource Efficiency, Scalability, Reduced Latency, Complex Error Handling

23
Q

Question 5:
What are the different patterns of microservice communication mentioned in the chapter?

a) Event-Driven and Request-Response
b) Synchronous and Asynchronous
c) HTTP and Message Queues
d) In-Process and Inter-Process

A

Answer: a) Event-Driven and Request-Response

24
Q

Question 6:
What are the advantages of event-driven communication in microservices?

a) Tight Coupling, Immediate Feedback, Resource Efficiency
b) Loose Coupling, Independent Services, Scalability, Flexibility
c) Increased Complexity, Resource Efficiency, Scalability, Flexibility
d) Loose Coupling, Tight Coupling, Independent Services, Flexibility

A

Answer: b) Loose Coupling, Independent Services, Scalability, Flexibility

25
Q

Question 7:
What are the disadvantages of event-driven communication in microservices?

a) Complex Error Handling, Increased Cognitive Load, Harder Implementation, More Latency
b) Simple Error Handling, Reduced Cognitive Load, Easier Implementation, More Latency
c) Complex Error Handling, Increased Cognitive Load, Easier Implementation, Less Latency
d) Simple Error Handling, Increased Cognitive Load, Harder Implementation, Less Latency

A

Answer: a) Complex Error Handling, Increased Cognitive Load, Harder Implementation, More Latency

26
Q

Question 8:
What is overhead in the context of microservice communication?

a) Additional computational resources or time required beyond the actual task
b) The main execution of a task
c) The main storage used by services
d) The network latency only

A

Answer: a) Additional computational resources or time required beyond the actual task

27
Q

Question 9:
What are the advantages of request-response communication in microservices?

a) Immediate Feedback, Simplicity, Predictability
b) Resource Efficiency, Scalability, Reduced Latency
c) Immediate Feedback, Resource Efficiency, Scalability
d) Simplicity, Increased Latency, Tight Coupling

A

Answer: a) Immediate Feedback, Simplicity, Predictability

28
Q

Question 10:
What are the disadvantages of request-response communication in microservices?

a) Loose Coupling, Scalability Issues, Lower Latency, Error Propagation
b) Tight Coupling, Scalability Issues, Higher Latency, Error Propagation
c) Loose Coupling, Immediate Feedback, Higher Latency, Error Propagation
d) Tight Coupling, Scalability Issues, Lower Latency, Resource Consumption

A

Answer: b) Tight Coupling, Scalability Issues, Higher Latency, Error Propagation

29
Q

Question 11:
What are the key considerations when choosing between synchronous and asynchronous communication in microservices?

a) Nature of the Task, Coupling, Performance, Complexity, Error Handling, Resource Utilization, Latency, Consistency
b) Coupling, Performance, Simplicity, Complexity, Error Handling, Resource Utilization, Latency, Consistency
c) Nature of the Task, Coupling, Performance, Simplicity, Error Handling, Resource Utilization, Latency, Consistency
d) Nature of the Task, Simplicity, Performance, Complexity, Error Handling, Resource Utilization, Latency, Consistency

A

Answer: a) Nature of the Task, Coupling, Performance, Complexity, Error Handling, Resource Utilization, Latency, Consistency

30
Q

Question 12:
What is eventual consistency?

a) The system will eventually reach a consistent state, even if updates are not immediate.
b) The system is always consistent immediately after an update.
c) The system never reaches a consistent state.
d) The system requires manual intervention to reach consistency.

A

Answer: a) The system will eventually reach a consistent state, even if updates are not immediate.

31
Q

Question 13:
What are sagas?

a) A sequence of transactions with compensating transactions for each step to handle failures.
b) A single transaction that updates all services at once.
c) A way to manually handle errors.
d) A form of synchronous communication.

A

Answer: a) A sequence of transactions with compensating transactions for each step to handle failures.

32
Q

Question 14:
What is idempotent event handling?

a) Ensuring that processing the same event multiple times does not change the outcome.
b) Ensuring that each event is processed exactly once.
c) Ensuring that events are never duplicated.
d) Ensuring that events are processed in the order they are received.

A

Answer: a) Ensuring that processing the same event multiple times does not change the outcome.