0
0
GCPcloud~10 mins

Topics and subscriptions in GCP - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Topics and subscriptions
Create Topic
Create Subscription
Publish Message
Message Stored in Topic
Subscription Receives Message
Subscriber Processes Message
Acknowledge Message
Message Removed from Subscription
This flow shows how a message moves from creation in a topic to delivery and acknowledgment by a subscription.
Execution Sample
GCP
1. Create topic 'news-updates'
2. Create subscription 'user1-sub'
3. Publish message 'Hello World'
4. Subscription receives message
5. Subscriber acknowledges message
This example shows creating a topic and subscription, publishing a message, and the subscriber receiving and acknowledging it.
Process Table
StepActionState ChangeMessage StateSubscription State
1Create topic 'news-updates'Topic 'news-updates' createdNo messagesNo subscriptions
2Create subscription 'user1-sub'Subscription 'user1-sub' createdNo messagesSubscription 'user1-sub' active, no messages
3Publish message 'Hello World'Message added to topicMessage 'Hello World' in topicSubscription 'user1-sub' active, message 'Hello World' pending delivery
4Subscription receives messageMessage delivered to subscriptionMessage 'Hello World' in topicSubscription 'user1-sub' has message 'Hello World' pending ack
5Subscriber acknowledges messageMessage acknowledged and removed from subscriptionMessage 'Hello World' in topicSubscription 'user1-sub' no pending messages
💡 Message acknowledged, no pending messages in subscription, flow ends
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5
TopicNoneCreated, no messagesCreated with 1 messageCreated with 1 messageCreated with 1 message
SubscriptionNoneCreated, no messagesCreated with 1 message pending deliveryHas 1 message pending ackNo messages pending
MessageNoneNone'Hello World' in topic'Hello World' delivered to subscriptionAcknowledged and removed
Key Moments - 3 Insights
Why does the message stay in the topic even after the subscription receives it?
Because Pub/Sub topics retain messages for a configurable retention duration (default 7 days), independent of acknowledgments by subscriptions. The subscription gets its own copy to process.
What happens if the subscriber does not acknowledge the message?
The message stays in the subscription as pending and can be redelivered until acknowledged, ensuring no message loss.
Can multiple subscriptions receive the same message from one topic?
Yes, each subscription gets its own copy of the message independently.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does the subscription first receive the message?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Check the 'Subscription State' column for when the message appears in the subscription
According to the variable tracker, what is the state of the message after step 5?
AMessage acknowledged and removed
BMessage still pending in subscription
CMessage deleted from topic
DMessage duplicated in subscription
💡 Hint
Look at the 'Message' row under 'After Step 5' in variable_tracker
If the subscriber never acknowledges the message, what would happen according to the flow?
AMessage is removed from topic immediately
BSubscription loses the message
CMessage remains pending in subscription and can be redelivered
DTopic deletes the subscription
💡 Hint
Refer to the key moment about message acknowledgment and subscription state
Concept Snapshot
Topics hold messages published by senders.
Subscriptions receive copies of messages from topics.
Subscribers pull messages from subscriptions.
Messages stay until acknowledged by subscribers.
Multiple subscriptions get independent copies.
Acknowledgment removes message from subscription.
Full Transcript
This visual execution shows how Google Cloud Pub/Sub topics and subscriptions work together. First, a topic is created to hold messages. Then, a subscription is created to receive messages from that topic. When a message is published, it is stored in the topic. The subscription gets its own copy of the message to deliver to subscribers. The subscriber processes the message and sends an acknowledgment. Only after acknowledgment is the message removed from the subscription. The topic retains the message for a retention period (default 7 days), regardless of acknowledgments. This ensures reliable delivery and no message loss. Multiple subscriptions can independently receive the same message from one topic.