Event Driven Architecture Flashcards
What is Event-Driven Architecture (EDA)?
Answer: EDA is a system design pattern where services communicate by producing and consuming events, allowing for loose coupling, scalability, and asynchronous communication between components.
When is Event-Driven Architecture a good fit in a Ruby on Rails application?
EDA is useful when you have multiple independent services that need to react to changes or events (e.g., user registration, order creation) without being tightly coupled, and when asynchronous processing is required.
What is a message broker, and how is it used in event-driven architecture?
A message broker is middleware (like Kafka or RabbitMQ) that routes messages (events) between producers and consumers, ensuring decoupling of services and allowing for asynchronous processing of events.
What’s the difference between Kafka and RabbitMQ?
Kafka: Best for high-throughput, distributed event streaming with strong support for real-time processing.
RabbitMQ: Best for reliable message delivery and more traditional message queuing with complex routing logic.
Why is asynchronous communication important in a Ruby on Rails application?
Asynchronous communication allows tasks (e.g., sending emails, processing large data) to be handled in the background without blocking the main application thread, improving performance and scalability.
How do message brokers decouple services in a Ruby on Rails app?
Message brokers decouple services by allowing them to communicate through events rather than direct calls, so each service operates independently, improving fault tolerance and scalability.
When should Kafka be used in a Ruby on Rails app?
Kafka is ideal when you need to handle a large volume of events, require real-time data streaming, or need durable, highly distributed systems that process events in order (e.g., analytics, logs, monitoring).
When should RabbitMQ be used in a Ruby on Rails app?
RabbitMQ is better when you need complex message routing, guaranteed message delivery, or need to process tasks in the background (e.g., job queues, user notifications).
What are producers and consumers in event-driven systems?
Producers: Services that emit events (e.g., a Rails app that creates a new user).
Consumers: Services that listen for and process those events (e.g., a background worker that sends a welcome email).
How are events handled in a Ruby on Rails app?
Rails applications can use gems like sneakers or racecar to handle message brokers (RabbitMQ or Kafka) for processing events in background jobs (using Sidekiq, Resque, etc.).
How do message brokers ensure reliability and scalability?
Message brokers like Kafka and RabbitMQ provide durable message storage, fault tolerance, and horizontal scalability, allowing your Rails app to process high volumes of events reliably.
What is eventual consistency in the context of EDA?
Eventual consistency means that, in an event-driven system, different services might not immediately reflect changes, but will eventually be consistent as events are processed asynchronously.
What is the difference between message queueing and event streaming?
Queueing (RabbitMQ): Messages are sent and processed once by consumers in a traditional queue.
Streaming (Kafka): Events are stored in a log and can be consumed by multiple consumers, allowing for real-time data processing and replayability.
How can a Ruby on Rails app act as an event producer?
A Rails app can produce events by publishing messages to a message broker (e.g., RabbitMQ or Kafka) whenever key actions occur, like user signups or purchases.
How can a Ruby on Rails app consume events?
A Rails app can consume events by subscribing to a message broker and processing events asynchronously using background jobs or services (e.g., sending notifications, updating databases).