Message Queues and Event-Driven Architecture Flashcards

(10 cards)

1
Q

What is a message queue, and why is it used?

A

A message queue stores and processes messages asynchronously. Example: RabbitMQ queues tasks like email sending, decoupling services for scalability.

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

What is event-driven architecture?

A

Event-driven architecture triggers actions based on events. Example: A user signup event in Kafka triggers a welcome email and analytics update.

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

How does RabbitMQ work in a backend?

A

RabbitMQ routes messages from producers to consumers via queues. Example: A Node.js app publishes a ‘user.created’ message, consumed by an email service.

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

How do you publish a message to RabbitMQ in Node.js?

A

```javascript
const amqp = require(‘amqplib’);
async function publish() {
const conn = await amqp.connect(‘amqp://localhost’);
const channel = await conn.createChannel();
await channel.assertQueue(‘tasks’);
channel.sendToQueue(‘tasks’, Buffer.from(‘Task 1’));
}
// Explanation: Sends a task to a queue for processing.
~~~

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

What is the difference between Kafka and RabbitMQ?

A

Kafka is a distributed log for high-throughput streaming; RabbitMQ is a traditional queue for task processing. Kafka suits analytics, RabbitMQ suits task queues.

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

How do you consume messages from a RabbitMQ queue?

A

```javascript
const amqp = require(‘amqplib’);
async function consume() {
const conn = await amqp.connect(‘amqp://localhost’);
const channel = await conn.createChannel();
await channel.assertQueue(‘tasks’);
channel.consume(‘tasks’, msg => console.log(msg.content.toString()));
}
// Explanation: Listens for tasks, processes messages.
~~~

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

What is a dead letter queue, and why is it used?

A

A dead letter queue stores messages that fail processing for later analysis. Example: In RabbitMQ, redirect failed tasks to a DLQ for debugging.

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

How do you ensure message reliability in a queue?

A

Use acknowledgments and persistent messages. Example: In RabbitMQ, set deliveryMode: 2 to persist messages, use channel.ack(msg) to confirm processing.

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

What is a publisher-subscriber pattern in event-driven systems?

A

Publishers send events to topics; subscribers receive relevant events. Example: Kafka topic ‘orders.created’ notifies payment and shipping services.

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

How do you scale a message queue system?

A

Partition queues/topics (e.g., Kafka partitions) and add consumers. Example: Scale Kafka by adding partitions and consumer groups for parallel processing.

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