Concise Answers Flashcards

(8 cards)

1
Q

Can you explain eventual consistency and when you would use it?

A

A — Answer:
Eventual consistency means a system does not reach a consistent state immediately, but all nodes will eventually converge to the same state.

C — Context:
It’s commonly used in distributed systems where asynchronous communication or replication is involved. Eventual consistency improves availability and performance but allows temporary discrepancies between nodes.

E — Example:
For example, when an order is placed, the InventoryService may update its stock slightly later. During that short period, the user might see stale inventory data, but eventually all services reflect the correct state.

⭐ Short version

Eventual consistency means that while a system may temporarily have inconsistent data, all nodes will eventually converge. It’s used in distributed systems to improve availability and performance, with temporary stale reads being acceptable.

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

“Can you explain eventual consistency and when you would use it?”

A

⭐ Senior-level improved answer (30–40 seconds)

A — Answer:
Eventual consistency means a system does not reach a consistent state immediately, but all nodes will eventually converge to the same state.

C — Context:
It’s commonly used in distributed systems where asynchronous communication or replication is involved. Eventual consistency improves availability and performance but allows temporary discrepancies between nodes.

E — Example:
For example, when an order is placed, the InventoryService may update its stock slightly later. During that short period, the user might see stale inventory data, but eventually all services reflect the correct state.

⭐ Short version

Eventual consistency means that while a system may temporarily have inconsistent data, all nodes will eventually converge. It’s used in distributed systems to improve availability and performance, with temporary stale reads being acceptable.

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

“What is idempotency, and why is it important in distributed systems?”

A

⭐ Senior-level improved answer (30–40 seconds)

A — Answer:
Idempotency means that performing the same operation multiple times produces the same result as performing it once.

C — Context:
It’s important in distributed systems because network issues or message brokers can deliver the same message more than once. Without idempotency, repeated processing could create inconsistent state.

E — Example:
For example, a PaymentService must ensure that if a “ChargeCustomer” message is delivered twice, the customer is not charged two times.

⭐ Short version (interviewer wants fast answers)

Idempotency means an operation has the same effect no matter how many times it’s executed. It’s crucial in distributed systems because retries or duplicate messages are common, and idempotency protects state consistency.

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

“Why do we use message queues like Kafka or RabbitMQ?”

A

⭐ Senior-level answer (30 seconds)

A — Answer:
We use message queues like Kafka and RabbitMQ to decouple services and make the system more reliable and scalable.

C — Context:
They allow asynchronous communication, so services don’t block each other.
They also handle retries, backpressure, and message durability, which increases system resilience.

E — Example:
For example, an OrderService can publish an “OrderCreated” event, and downstream services like Notification or Billing can process it independently without impacting the core workflow.

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

“Can you explain what a Saga pattern is and when you would use it in microservices?”

A

A — Answer:
The Saga pattern is used in microservices to maintain data consistency across multiple services without using distributed transactions.

C — Context:
It works by breaking a process into a series of local transactions that publish events. If any transaction fails, compensating transactions are triggered to undo previous steps, ensuring the system remains consistent.

E — Example:
For example, when an order is placed, it triggers events to Inventory and Payment services. If the Payment service fails, compensating transactions can rollback the Inventory update, so the system stays consistent without using a global transaction.

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

“What is the difference between synchronous and asynchronous communication in microservices, and when would you use each?”

A

⭐ Senior-level improved answer (40–50 seconds)

A — Answer:
Synchronous communication requires the caller to wait for a response from the service, while asynchronous communication allows the caller to continue without waiting.

C — Context:
Synchronous calls are simple and provide immediate results but can increase latency and reduce throughput, as each request blocks the caller.
Asynchronous communication, often implemented via message brokers, decouples services, improves throughput, and allows horizontal scaling, though responses may be delayed.

E — Example:
For example, a banking system that requires immediate consistency might use synchronous calls.
In contrast, an e-commerce system can use asynchronous messaging to update inventory and notify other services, improving scalability and resilience.

⭐ Short version (for quick answer)

Synchronous communication waits for a response and is good for high consistency, but may reduce throughput. Asynchronous communication uses message brokers, decouples services, and improves scalability, though results may be delayed.

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

What is the Outbox pattern, and why would you use it in microservices?”

A

⭐ Senior-level improved answer (30–40 seconds)

A — Answer:
The Outbox pattern is used in microservices to ensure reliable message delivery and maintain consistency between the database and event publishing.

C — Context:
It works by writing both the business data and the event to a dedicated “outbox” table in a single transaction. A separate process then reads pending events from this table and publishes them. If the transaction fails, nothing is published, ensuring atomicity and eventual consistency.

E — Example:
For example, when an OrderService creates a new order, it writes the order to the database and the corresponding “OrderCreated” event to the outbox table. A background process then publishes the event to other services, ensuring no event is lost.

⭐ Short version

The Outbox pattern ensures atomic writes and reliable event publishing by storing events in a table within the same transaction as the business data, then publishing them asynchronously.

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