Pub Sub Flashcards

1
Q

What is Pub/Sub?

A

Pub/Sub is a fully-managed messaging system offered by GCP.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Do Pub/Sub servers run in all GCP regions around the world or just in specific regions?

A

Pub/Sub servers run in all GCP regions around the world.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the main differences between Pub/Sub and Pub/Sub Lite?

A
  1. Pub/Subs is global while Pub/Sub Lite is regional or zonal.
  2. Pub/Sub has more features and costs more and Pub/Sub Lite has less features but also costs less.
  3. Pub/Sub supports message-based parallelism and Pub/Sub Lite supports partition-based parallelism.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Generally speaking, what are the 3 components that make up Pub/Sub’s billing structure?

A
  1. Throughput
  2. Data transfer
  3. Storage data

Throughput is the amount of data published to a Topic or read from a subscription.

Data transfer is throughput that crosses a region. For example, a Publisher is in region A and the Subscriber is in region B.

Storage data are the messages retained by a Topic or acknowledged messages retained by a Subscription.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the main difference between Pub/Sub and Cloud Tasks?

A

Pub/Sub is designed so that publishers are unaware of subscribers and vice versa. With Cloud Tasks, the publishers are aware of the subscribers and have control over them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Is Pub/Sub designed for end-user-to-service communication or service-to-service communication?

A

Pub/Sub is designed for service-to-service communication.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In general, what are the different stages of a message lifecycle?

A
  1. Publisher publishes a message to a Topic
  2. Pub/Sub stores the message in the nearest region to the publisher and replicates it across multiple zones
  3. Pub/Sub sends an ack to the Publisher
  4. Pub/Sub copies the message and delivers it to an attached Subscription
  5. Subscriber consumes the message from the Subscription and sends Pub/Sub an acknowledgement
  6. After at least one subscriber from each Subscription has acknowledged the message, Pub/Sub deletes it from storage.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When a subscriber pulls messages from a Subscription, it connects to the nearest Pub/Sub server which aggregates and prepares messages for delivery to the subscriber.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Does Google recommend using the same publisher client object to publish messages to a specific topic or creating a new publisher client object for each message that you want to publish?

A

Google recommends using the same publisher client object to publish messages to a specific topic so that time is not wasted establishing an authorized connection for each publishing request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a Topic?

A

A topic is message feed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

By default, for how long will a Topic store messages and does it cost money?

A

By default, a Topic will not store any messages. However, a Topic can be configured to store messages for up to 31 days. Storing messages at the Topic level costs money but is the most economical since all attached Subscriptions will be able to access those messages without incurring storage costs of their own.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can a Topic have multiple Subscriptions?

A

Yes. However, a Subscription can only be attached to a single Topic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the 2 types of schema frameworks that Pub/Sub supports?

A
  1. Avro
  2. Protocol Buffers

Schemas are attached to a Topic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does a Subscription represent?

A

A Subscription represents an interest in receiving messages from a Topic. A Subscription is attached to a Topic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

By default, how long will a Subscription retain unacknowledged messages and does it cost money?

A

7 days, which is the maximum. Unacknowledged messages are free for the first 24 hours.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can a Subscription be configured to retain acknowledged messages and does it cost money?

A

Yes, acknowledged messages can be retained for a maximum of 7 days. This feature is no free.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

If a Subscription has multiple subscribers, how are messages allocated to those subscribers?

A

Each subscriber will receive a subset of the messages from the Subscription.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How does Pub/Sub minimize the possibility of delivering the same message to multiple subscribers?

A

While a subscriber is processing a message during the ack deadline, Pub/Sub tries not to deliver the message to other subscribers. Keep in mind, this is done on a best effort basis. If the possibility of duplications needs to be further reduced, think about enabling Exactly Once Delivery for the Subscription.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What happens if a subscriber fails to acknowledge a message during the ack deadline?

A

Pub/Sub will redeliver the message to the same or another subscriber.

20
Q

What are the 3 different types of Subscriptions?

A
  1. Pull
  2. Push
  3. Export

Pull supports both traditional pull and streaming pull.
Push supports an HTTP POST endpoint and Payload Unwrapping
Export supports BigQuery and Cloud Storage directly

21
Q

By default, which message delivery mode does a subscriber client library use?

A

Asynchronous streaming pull

22
Q

Does Pub/Sub support stream processing?

A

Not natively. However, you can use Dataflow to implement stream processing. This is similar to how Kafka uses KSQL for stream processing.

23
Q

Does Pub/Sub support message replay?

A

Yes. All you need to do is select a message timestamp on a Subscription using Cloud Console or gcloud, and you can replay the message. However, keep in mind that all messages after the message you selected will be unacknowledged.

24
Q

Does Pub/Sub support ordered processing?

A

If messages are published in the same region with the same Ordering Key and the Subscription has Message Ordering enabled, subscribers will process those messages in the order in which they were published.

25
Q

Does Pub/Sub support exactly once message delivery?

A

If messages are being processed within the same region, and the subscribers use a Pull Subscription, then yes. When the Subscription sends a message to a subscriber it attaches an acknowledgement ID. If the subscriber fails to acknowledge the message before the ack deadline, the acknowledgement ID is expired and Pub/Sub redelivers the message. An expired acknowledgement ID will not allow a subscriber to acknowledge a message after the ack deadline. Therefore, once the message is redelivered and processed within the ack deadline, there won’t be any duplicates.

26
Q

Does Pub/Sub support message dedup?

A

Not natively. However, you can use Dataflow to implement dedup logic.

27
Q

What is the maximum message size?

A

10 MB. However, if you need to transmit messages that are larger in size, you can have a publisher store a message in Cloud Store and publish its URL to a Topic. Then have a subscriber process the URL and retrieve the message from Cloud Storage. Remember, Cloud Storage supports up to 5 TB per object.

28
Q

If you need a Subscription to retain messages for longer than 7 days, what can you do?

A

You configure the corresponding Topic to store messages for longer than 7 days. This gives the Subscription access to both acknowledged and unacknowledged messages without incurring storage costs at the Subscription leve.

29
Q

What is a Dead-letter Topic?

A

A Dead-letter Topic is a Topic where unacknowledged messages are published whenever a subscriber fails to acknowledge a message for a configurable number of times. The Dead-letter Topic feature is set at the Subscription level.

30
Q

What are the 5 components that make up a message?

A
  1. Message ID
  2. Timestamp
  3. Attributes
  4. Message Data
  5. Ordering Key

Message ID and Timestamp are created by Pub/Sub.
Attributes are user-defined key-value pairs that server as metadata.
Message Data is the actual content of a message and cab be in text or binary form.
Ordering Key is an optional user-defined key that is used to implement ordered messages.

For example:

{
  "data": string,
  "attributes": {
    string: string,
    ...
  },
  "messageId": string,
  "publishTime": string,
  "orderingKey": string
}
31
Q

If you want to select the regions where your messages should be stored, what can you do?

A

You can apply a Message Storage Policy at the Topic level.

32
Q

If you need a Topic to ingest a stream of data from external sources, what can you do?

A

You can use Enable Ingestion at the Topic level.

33
Q

If you need to control the rate at which publishers are publishing messages or subscribers are consuming messages so that they don’t get overladed, what can you do?

A

You can configure Flow Control Setting through client libraries.

34
Q

Does a client library enable batch messaging for publishers by default?

A

Yes. This is important because batch messaging reduces cost but increases latency.

35
Q

By default, how many days does it take for a Subscription to become expired for inactivity?

A

31 days.

36
Q

If the ack deadline is defined in both the Subscription and the subscriber level through a client library, which one takes precedence?

A

The subscriber takes precedence.

37
Q

When using a Push Subscription, what determines whether a message was acknowledged or not?

A

If the subscriber returns a successful HTTP response, the message was acknowledged. If not, then it wasn’t.

38
Q

Pub/Sub dynamically adjusts the rate of push requests based on the rate at which it receives success responses.

A
39
Q

What happens when a negative acknowledgement is sent back to a Push Subscription?

A

Push Backoff is enabled. Essentially, it’s an exponential backoff algorithm that determines the amount of time the Subscription should delay when sending messages. Push Backoff can not be modified.

40
Q

What are the 2 types of Subscription retry policies?

A
  1. Retry immediately
  2. Exponential backoff

These policies are independent of Push Backoff when using Push Subscriptions.

41
Q

What is a Snapshot?

A

A Snapshot is a point-in-time view of the message acknowledgement state of a subscription.

42
Q

Does the subscriber client library automatically extend the ack deadline when messages are not acknowledged?

A

Yes. The subscriber client sends a “modify ack deadline” request to Pub/Sub, increasing the ack deadline for that message up to 1 hour. This can be configured.

43
Q

Should you use both Message Ordering and Dataflow at the same time to implement message ordering logic?

A

No. Only use one of them.

44
Q

Can Subscriptions filter messages by message data?

A

No. Messages can only be filtered by message attributes.

45
Q

Is a subscriber client library needed for a Push Subscription?

A

No. This is actually one of the reasons for using a Push Subscription when you are not able to import a client library into your subscriber application.