Google Cloud capstone: verify, recover and tear down
Verify a release, handle duplicates, run one failure drill with rollback or replay, review IAM and cost, and tear everything down.
By Invicly Tech, , in Google Cloud Engineering and Services. About 9 minutes to read.
In short
A service is done only when you can show it works, survive a failure and remove it cleanly. You verify with logs and a query, prove that duplicates are harmless, drill a failure, roll back a bad revision, review IAM and cost, and then destroy everything.
Think of it like this: It is the handover check on a new building: test the alarm, walk the exits, read the meter, then hand back the keys.
Explained simply
A running service is not a finished service. In this last topic you prove it works, break it on purpose, fix it and clean up.
First you check evidence. Read the logs and run a small query to count your orders. Then send the same order twice and show that only one record exists. That proves your duplicate handling.
Next is a failure drill. Deploy a version of the consumer that fails. Watch Pub/Sub retry and then park the messages in the dead-letter topic. Switch traffic back to the last good version, then replay the parked messages.
Last, review who can do what and what it cost, then delete everything. Check that nothing is left. Certifications such as Associate Cloud Engineer and Professional Cloud Architect are optional follow-ons. This project is good practice for the topics they cover.
Press Play on a diagram to walk through it one step at a time.
- 1Break it
Deploy a consumer revision that returns 500 for some orders.
- 2Watch
See retries in logs and messages arriving in the dead-letter topic.
- 3Fix
Roll back traffic to the last good revision.
- 4Replay
Move dead-lettered messages back or seek the subscription.
- 5Verify
Query storage and confirm each order ID appears exactly once.
- Back to step 1
- 1Evidence
Save logs, query output and SLO numbers.
- 2IAM review
List roles per service account and remove extras.
- 3Cost review
Check the billing report by label.
- 4Destroy
Run terraform destroy.
- 5Confirm
List resources and check nothing is left.
- Order in storage
- Log line with order ID
- Verification query output
- Duplicate sent twice, one record
- Failure drill with DLQ
- Rollback and replay result
- IAM roles per account
- Cost report by label
- Resource list after destroy
In depth
Verify with logs and a query
Prerequisites: the deployed service from the last topic and permission to read logs and run queries. In Logs Explorer, filter on the consumer's resource type cloud_run_revision and the service name, and look for your order ID. For BigQuery persistence, a query such as SELECT order_id, COUNT(*) FROM orders.events GROUP BY order_id shows each ID and how many times it was stored. Evidence you expect: one log line per delivery, and a count of 1 for each order ID after the duplicate test. Save the query text and result as proof. There is nothing to roll back here, because the checks only read data.
- Use structured logs with an order_id field
- Count rows by order ID to prove dedupe
- Record the time of each check
Drill a failure, then roll back and replay
Deploy a consumer revision that returns 500 for one order ID. Publish three orders. You should see retries in the logs, and after the maximum attempts the bad message appears in the dead-letter subscription. The healthy orders are stored. Now move traffic back with gcloud run services update-traffic consumer --to-revisions=REVISION_NAME=100 --region=REGION. Then replay. The dead-letter topic needs a pull subscription so messages are retained, and you republish them to the main topic. If you want to replay from the main subscription, it must retain acknowledged messages, and then gcloud pubsub subscriptions seek with a time rewinds it. Evidence: the stored count rises and the DLQ is empty.
- Operator to Cloud Run: Deploy failing revision1Deploy failing revision
- Pub/Sub to Cloud Run: Deliver order, get 5002Deliver order, get 500
- 3Retry, then dead-letterPub/Sub to Pub/Sub: Retry, then dead-letter
- Operator to Cloud Run: Route traffic to good revision4Route traffic to good revision
- Operator to Pub/Sub: Republish dead-lettered messages5Republish dead-lettered messages
- Pub/Sub to Cloud Run: Deliver again, get 2006Deliver again, get 200
IAM review, cost review and destroy
Open IAM and list the roles for each service account. Compare with the identity map from the design. Remove anything extra, and look for any basic role. Then open billing reports and group by the labels you set, to see the cost per resource type. Expect very small numbers for a short test. Finally run terraform destroy and confirm. Cloud Storage buckets with objects may need force_destroy to be set, or the objects emptied first. Afterwards list the project's resources, for example with gcloud run services list and gcloud pubsub topics list, and consider deleting the project if it was made for this exercise.
- Check Artifact Registry images, which Terraform may not own
- Check BigQuery datasets for leftover tables
- Delete the project only if it holds nothing else
Learn it in 5 short steps
About 1h 10m each. Track them with a timer in your plan.
- 1Verify with logs and a BigQuery query~1h 10m
- 2Prove duplicate handling~1h 10m
- 3Drill a failure and replay dead letters~1h 10m
- 4Roll back a revision~1h 10m
- 5Review IAM and cost, then destroy~1h 10m
Key points
- Verification needs evidence: a log line, a query result and a count, not a feeling that it worked.
- Send the same event twice on purpose and show that only one record exists.
- Roll back with gcloud run services update-traffic, sending 100 percent of traffic to a known good revision.
- To replay, use subscription seek on a retained subscription, or republish dead-lettered messages once the bug is fixed.
- Destroy with terraform destroy, then list the project's resources to confirm nothing remains.
Key terms
Tap a card to flip it. 0/5 known
Examples
Proving duplicate handling
Publish the same order twice with the same order ID. Then count. If the count is 2, the dedupe is missing or keyed on the wrong field, such as messageId, which is different for each publish.
for i in 1 2; do
gcloud pubsub topics publish order-events \
--message='{"order_id":"o-2001","total":10}'
done
bq query --use_legacy_sql=false \
'SELECT order_id, COUNT(*) c FROM orders.events GROUP BY order_id'Rolling back a revision
List revisions, pick the last good one, and send all traffic to it. The bad revision stays available, so you can read its logs. Check the service afterwards by sending a test order.
gcloud run revisions list --service=consumer --region=us-central1
gcloud run services update-traffic consumer \
--region=us-central1 \
--to-revisions=consumer-00005-abc=100Quick reference
- Verify with a log line and a count by order ID.
- Rollback: gcloud run services update-traffic SERVICE --to-revisions=REV=100.
- Seek only works on subscriptions that retain acknowledged messages.
- Dead-letter topics need a subscription or the messages are not kept.
- Review IAM against your identity map; remove basic roles.
- Group billing reports by label to see cost per part.
- terraform destroy, then list resources to confirm.
- Certifications are optional: Associate Cloud Engineer, Professional Cloud Architect.
Common mistakes
- Declaring success after one message works, without a duplicate test or a failure drill.
- Trying to seek or replay when the subscription never kept acknowledged messages.
- Running destroy and not checking afterwards, leaving a bucket or dataset that still holds data.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Write a query that shows how many times each order ID was stored.
- Exercise 2medium
Write the commands to find the last good revision and roll back to it.
- Exercise 3hard
Write a teardown checklist with a way to confirm each item is gone.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- How do I replay messages after fixing a bug?
- Republish the dead-lettered messages to the main topic, or seek a subscription that kept acknowledged messages back to a time. Your consumer must handle repeats safely.
- Do I need a certification after this?
- No. Associate Cloud Engineer and Professional Cloud Architect are optional. Check the current exam guides on the Google Cloud certification site to see how this work maps to them.
- How do I know what the exercise cost?
- Open Cloud Billing reports and group by the labels you set. For a short run the amount is usually very small.