QA
Intermediate LevelSoftware Engineering Principles

What is Event-Driven Architecture (EDA) and how do Event Handlers communicate asynchronously?

❓ Interview Prompt: Explain Event-Driven Architecture (EDA), Event Producers/Consumers, Message Brokers, and Saga Pattern (Choreography vs Orchestration).

Event-Driven Architecture (EDA) connects decoupled microservices by publishing and consuming asynchronous event messages:

Saga Pattern for Distributed Transactions:

When a transaction spans multiple microservices, Sagas coordinate execution via a sequence of local transactions:

•
Choreography: Each service listens to events and publishes new events independently.
•
Orchestration: A central Saga Orchestrator tells participating services which local transaction to execute and handles compensating rollback actions if a step fails.

Code Implementation Example

typescript
// Saga Compensating Action Example
class OrderSagaOrchestrator {
  async executeOrder(orderId: string) {
    try {
      await inventoryService.reserveStock(orderId);
      await paymentService.chargeCard(orderId); // Fails!
    } catch (err) {
      // Compensating Action: Rollback previous local transaction!
      await inventoryService.releaseStock(orderId);
    }
  }
}
💡Executing compensating rollback actions in Saga Orchestration.
🎯 Interview Key Takeaway

Use Event-Driven Architecture and Saga patterns to manage distributed microservice workflows asynchronously.

#Event Driven#Saga Pattern#Microservices#Intermediate
Back to all Software Engineering Principles Questions→

More Software Engineering Principles Interview Questions

Beginner LevelSoftware Engineering Principles

Explain the 5 SOLID Principles of Object-Oriented Software Design with practical refactoring examples.

Beginner LevelSoftware Engineering Principles

What are DRY (Don't Repeat Yourself), KISS (Keep It Simple, Stupid), and YAGNI (You Aren't Gonna Need It)?

Beginner LevelSoftware Engineering Principles

Why is Composition Over Inheritance a fundamental object-oriented design principle?