Best way to implement Google Pub/Sub Subscribe + HTTP Rest API + Database

I want to ask about the best way to implement Pub Sub with REST API.

I want to subscribe data from Pub/Sub, then I send the data via HTTP Rest API, which hits every endpoint per subscribe. And then, save into database after hit endpoint.

So, there are 3 jobs in the service.

  1. Subscribe to Pub/Sub
  2. Send payload from step 1 via HTTP Rest API
  3. Save data into database.

My first approach will bee create two different service.

  1. First service to subscribe data from Pub/Sub.
  2. Second service to send payload data from step 1 to HTTP Rest API and in this service, save payload into database.

What is the best way to implement it?

What if the data from Pub/Sub becomes too much. Is it possible that the service could be down or slow?

I don't have much experience with Pub/Sub.

Thank you.


Because your architecture is asynchronous, I propose you that approach

  1. PubSub push subscription (initial topic)
  2. Cloud Run service that call the HTTP service. If successful, publish a message in PubSub 3 PubSub push subscription (topic on successful HTTP rest API call)
  3. Cloud Run service that save the data in database.

That architecture is idempotent and scalable. You can play with the concurrency parameter of Cloud Run to save money or speed up the process.