0
0
Microservicessystem_design~10 mins

Outbox pattern for reliable events in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to insert an event into the outbox table within the same transaction.

Microservices
BEGIN TRANSACTION;
INSERT INTO orders (id, status) VALUES (123, 'created');
INSERT INTO outbox (event_type, payload) VALUES ('OrderCreated', [1]);
COMMIT;
Drag options to blanks, or click blank then click option'
A'{"orderId":123}'
B123
CNULL
Dorder_data
Attempts:
3 left
💡 Hint
Common Mistakes
Inserting NULL instead of event data.
Using a raw number instead of a JSON string.
Forgetting to insert the event in the same transaction.
2fill in blank
medium

Complete the code to select unprocessed events from the outbox for publishing.

Microservices
SELECT id, event_type, payload FROM outbox WHERE processed = [1];
Drag options to blanks, or click blank then click option'
ATRUE
BNULL
C1
DFALSE
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting events where processed is TRUE (already processed).
Using NULL which does not filter correctly.
3fill in blank
hard

Fix the error in the code that marks an event as processed after publishing.

Microservices
UPDATE outbox SET processed = [1] WHERE id = event_id;
Drag options to blanks, or click blank then click option'
AFALSE
BTRUE
C0
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Setting processed to FALSE or 0 after publishing.
Setting processed to NULL which is ambiguous.
4fill in blank
hard

Fill both blanks to implement a retry mechanism that selects events with less than 5 attempts and marks them as processing.

Microservices
SELECT id FROM outbox WHERE processed = FALSE AND attempts [1] 5;
UPDATE outbox SET processing = TRUE WHERE id = [2];
Drag options to blanks, or click blank then click option'
A<
B>
C=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' to filter attempts.
Using '!=' instead of '=' in the update statement.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps event IDs to payloads for unprocessed events with attempts less than 3.

Microservices
events = {event['id']: event[[1]] for event in events_list if event[[2]] [3] 3 and event['processed'] == False}
Drag options to blanks, or click blank then click option'
Apayload
Battempts
C<
Dprocessed
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'processed' as the value instead of 'payload'.
Using '>' instead of '<' for attempts comparison.