Bird
Raised Fist0
Microservicessystem_design~20 mins

Event replay in Microservices - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Event Replay Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary purpose of event replay in microservices?

In a microservices architecture, event replay is often used. What is its main goal?

ATo rebuild the current state of a service by reprocessing past events
BTo send real-time notifications to users about new events
CTo delete old events from the event store to save space
DTo encrypt events before sending them to other services
Attempts:
2 left
💡 Hint

Think about why a service might need to process old events again.

Architecture
intermediate
2:00remaining
Which component is essential for enabling event replay in a microservices system?

To support event replay, which component must be part of the system design?

AA message queue that deletes events after delivery
BA load balancer to distribute incoming requests
CA cache to store the latest state snapshot only
DAn event store that persists all events in order
Attempts:
2 left
💡 Hint

Consider where events must be kept to allow replay.

scaling
advanced
2:00remaining
How to efficiently scale event replay when the event log grows very large?

When the event log becomes huge, replaying all events can be slow. Which approach best improves replay efficiency?

AUse snapshots to save intermediate states and replay only recent events
BDelete old events regularly to keep the log small
CReplay events on multiple services simultaneously without coordination
DReplay events only during off-peak hours to reduce load
Attempts:
2 left
💡 Hint

Think about saving partial progress to avoid replaying everything from the start.

tradeoff
advanced
2:00remaining
What is a key tradeoff when enabling event replay in microservices?

Choosing to keep all events for replay has benefits and drawbacks. What is a major tradeoff?

AReduced network traffic versus higher latency in event processing
BIncreased storage and complexity versus ability to recover and audit state
CSimpler codebase versus inability to handle failures
DFaster response times versus less accurate state reconstruction
Attempts:
2 left
💡 Hint

Consider what storing all events costs and what benefits it brings.

estimation
expert
3:00remaining
Estimate the storage needed for event replay given event size and volume

A microservice generates 1000 events per second. Each event is 1 KB in size. How much storage is needed to keep events for 30 days to support event replay?

AAbout 26 TB
BAbout 260 GB
CAbout 2.6 TB
DAbout 26 GB
Attempts:
2 left
💡 Hint

Calculate total events per day, multiply by event size, then by 30 days.

Practice

(1/5)
1. What is the main purpose of event replay in a microservices architecture?
easy
A. To balance load between microservices
B. To rebuild system state by reprocessing stored events in order
C. To send real-time notifications to users
D. To encrypt data during transmission

Solution

  1. Step 1: Understand event replay concept

    Event replay means using stored events to reconstruct the current state of a system by processing them again in the order they occurred.
  2. Step 2: Identify the main purpose

    This process helps recover system state after failures or to debug by looking at past events, not for notifications, load balancing, or encryption.
  3. Final Answer:

    To rebuild system state by reprocessing stored events in order -> Option B
  4. Quick Check:

    Event replay = rebuild state [OK]
Hint: Event replay means replaying past events to restore state [OK]
Common Mistakes:
  • Confusing event replay with real-time messaging
  • Thinking event replay balances load
  • Assuming event replay encrypts data
2. Which of the following is the correct way to ensure events are replayed in the right order?
easy
A. Ignore event order since it doesn't affect state
B. Replay events randomly to speed up processing
C. Replay only the latest event to save resources
D. Store events with timestamps and replay by sorting them chronologically

Solution

  1. Step 1: Understand importance of event order

    Events must be replayed in the exact order they occurred to correctly rebuild system state.
  2. Step 2: Identify correct ordering method

    Using timestamps to sort events chronologically ensures the correct sequence during replay.
  3. Final Answer:

    Store events with timestamps and replay by sorting them chronologically -> Option D
  4. Quick Check:

    Correct event order = chronological replay [OK]
Hint: Replay events by timestamp order to keep state consistent [OK]
Common Mistakes:
  • Replaying events randomly
  • Skipping older events
  • Ignoring event order
3. Given the following event log stored as tuples (timestamp, event):
[(1, 'create'), (3, 'update'), (2, 'update'), (4, 'delete')]
What is the correct order of events during replay?
medium
A. [('update'), ('create'), ('delete'), ('update')]
B. [('delete'), ('update'), ('create'), ('update')]
C. [('create'), ('update'), ('update'), ('delete')]
D. [('update'), ('delete'), ('create'), ('update')]

Solution

  1. Step 1: Sort events by timestamp

    Sort the list by the first element (timestamp): 1, 2, 3, 4.
  2. Step 2: Extract event names in sorted order

    Events in order: 'create' (1), 'update' (2), 'update' (3), 'delete' (4).
  3. Final Answer:

    [('create'), ('update'), ('update'), ('delete')] -> Option C
  4. Quick Check:

    Sorted timestamps = 1,2,3,4 [OK]
Hint: Sort by timestamp, then list events in that order [OK]
Common Mistakes:
  • Ignoring timestamp order
  • Mixing event sequence
  • Assuming original list order is correct
4. A microservice tries to replay events but the system state is incorrect after replay. Which issue is most likely causing this?
medium
A. Events were replayed out of order
B. Events were encrypted during replay
C. Events were replayed multiple times in parallel
D. Events were filtered by type before replay

Solution

  1. Step 1: Analyze replay error cause

    Incorrect system state after replay usually means the event sequence was not preserved.
  2. Step 2: Identify the most common cause

    Replaying events out of order breaks the state reconstruction logic, causing errors.
  3. Final Answer:

    Events were replayed out of order -> Option A
  4. Quick Check:

    Out-of-order replay = wrong state [OK]
Hint: Check event order first when state is wrong after replay [OK]
Common Mistakes:
  • Blaming encryption which doesn't affect replay order
  • Assuming parallel replay is always safe
  • Filtering events without understanding impact
5. You want to add a new feature that analyzes historical user actions using event replay. Which design choice best supports this without affecting live system performance?
hard
A. Replay events asynchronously from a separate event store copy
B. Replay events synchronously on the main database during user requests
C. Replay only the latest event repeatedly for analysis
D. Skip event replay and query live data directly

Solution

  1. Step 1: Understand impact of replay on live system

    Replaying events synchronously during user requests can slow down or disrupt the live system.
  2. Step 2: Choose design for performance and safety

    Using a separate copy of the event store and replaying asynchronously isolates analysis from live traffic, preserving performance.
  3. Final Answer:

    Replay events asynchronously from a separate event store copy -> Option A
  4. Quick Check:

    Async replay on copy = no live impact [OK]
Hint: Use async replay on separate store to avoid live system load [OK]
Common Mistakes:
  • Replaying synchronously blocking live requests
  • Analyzing only latest event missing history
  • Ignoring benefits of event replay for analysis