Google did answer the question here
https://cloud.google.com/pubsub/faq
But I'm still unclear on which scenarios would each be used for?
Is there something that pub sub can do which GCM can't?
Google Cloud Pub/Sub provides messaging between applications. Cloud Pub/Sub is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher applications can send messages to a "topic" and other applications can subscribe to that topic to receive the messages.
In general, both are very solid Stream processing systems. The point which make the huge difference is that Pubsub is a cloud service attached to GCP whereas Apache Kafka can be used in both Cloud and On-prem. Update (April 6th 2021): Finally Kafka without Zookeeper.
The Pub/Sub server sends each message as an HTTPS request to the subscriber client at a pre-configured endpoint. This request is shown as a PushRequest in the image.
Google Cloud Messaging (GCM) is a service that allows you to send push notifications from your server to your users' Android devices, and also to receive messages from devices on the same connection.
The primary difference between Google Cloud Pub/Sub and GCM is the points for scaling. GCM is designed to scale to many individual publishers and subscribers, on the order of end user devices such as phones. Cloud Pub/Sub, on the other hand, is designed to scale to very large throughput from/to fewer publishers and subscribers.
The two could actually be used together. Imagine, for example, you were building a stock market notification app where users get notifications when certain stocks reach certain prices. You set up a service that pulls stock prices from a variety of sources, processes them, and then publishes stock prices via Cloud Pub/Sub. You have a separate service that subscribes to Cloud Pub/Sub and gets these stock prices. It then determines which ones are of interest to which users of the app and uses GCM to send notifications to those interested.
Cloud Pub/Sub allows you to decouple your ingestion from different sources and your service that sends updates to users. Your services would be the publishers and subscribers to Cloud Pub/Sub with a large feed of data moving between them. The throughput on notification to individual users will be much smaller and you have a lot more subscribers, so GCM would be the proper system to use for that part.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With