- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud
Implementing Retry and Idempotency in Google Cloud Pub/Sub
This guided lab focuses on improving the reliability of a Google Cloud Pub/Sub order-processing application through bounded retries with exponential backoff and Firestore-based idempotency. The implementation demonstrates deterministic dependency failures, retry exhaustion, and successful recovery. Acknowledgement-loss simulation and duplicate message delivery validate that the order completes exactly once, with consistent business records in Firestore.
Lab Info
Table of Contents
-
Challenge
Reproduce the dependency failure and determine how the current application handles it
- Establish a baseline Pub/Sub order-processing scenario with a controlled, deterministic dependency failure.
- Examine how the existing subscriber handles the failure without application-level retry.
- Identify the impact on order processing, including message redelivery eligibility and the absence of completed Firestore business records.
-
Challenge
Add bounded retry behavior with exponential backoff
- Introduce application-level retry handling for transient dependency failures, limited to three processing attempts.
- Apply exponential backoff with increasing delays of one and two seconds between attempts.
- Demonstrate retry exhaustion when the dependency remains unavailable, preventing incomplete business operations from being committed.
-
Challenge
Add an idempotency mechanism for repeated delivery or execution
- Establish a unique business order ID as the idempotency key to identify previously processed operations.
- Use Firestore transactions to maintain consistent order, receipt, and completion records.
- Prevent duplicate business operations by recognizing repeated executions and preserving the original transaction results.
-
Challenge
Re-run the failure condition and allow the dependency to recover
- Demonstrate the improved application's behavior under the same controlled dependency failure.
- Validate successful recovery after two transient failures, with processing completing on the third attempt.
- Confirm successful order completion and Pub/Sub message acknowledgement following the Firestore transaction.
-
Challenge
Verify the operation completes once with the expected final state
- Simulate acknowledgement loss and message redelivery to evaluate duplicate-processing protection.
- Validate idempotency when the same business order is delivered again through a new Pub/Sub message.
- Confirm the final Firestore state contains one completed order, one issued receipt, and a completion count of exactly one.
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.