问题
We are designing out our listening side of Google PubSub and will be using Google Functions for this. There are two choices, push and a backend function. Push using Http and will push messages to the function. backend function uses triggering to invoke the function.
Where we are having trouble is deciding which approach may be better for our application. We have not been able to find a list of differences between these two methods within the Google documentation.
Some things we have noticed are that:
- Http function use an Expressjs structure where backend functions are only a function.
- It appears message retires is only available for backend functions.
- It isn't clear if and how dead letter queues work with backend functions.
- Are there differences between the number of messages per second which can be handled?
- So many more items we aren't thinking of to ask...
The question here is, what should be determined to help choose between an http function or a backend function for receiving PubSub messages?
回答1:
My point of view is more in term of security and usability.
Backend function
- Built in authentication between the pubsub and the function
- No public exposure
- No dead letter topic capacity
- No message filtering capacity
- No ordering key capacity
Push Function
- Require to manage yourself the security (deploy the function with
no-allow-unauthenticated
and put a service account in your push subscription to ensure the security) - Public exposure (ingress control set to internal prevent all external call, pubsub push subscription included, you can't use this feature)
- Trigger by PubSub and by other processes (great for testing or for replaying events)
- Dead letter topic, retry policies, ordering key and filtering available.
- More portable format. You can push to any endpoints: Cloud Functions, Cloud Run, Compute Engine, or even external endpoint. You are less locked-in
In both cases, the retries are possibles
So, I prefer the push subscription + http Cloud Function model. The number of messages per second should be a concern (up to 250k messages per second at least)
回答2:
Unfortunately I cannot comment, so I have a write a separate answer.
In my personal experience and opinion, if possible, I would always prefer a Pub/Sub triggered cloud function (actually this is the 'push' subscription).
My main reasoning:
- More simple security, thus less room for mistakes, less chances to expose the endpoint publicly, for example.
- Messages in a Pub/Sub - kind of a mechanism for horizontal scalability (use it as a buffer). The client publishes a message and 'forgets'...
- More than one (type of) cloud functions can be triggered from one message ('in parallel').
Drawbacks (from my personal point of view):
- Implicit acknowledgement
- No ordering or filtering
来源:https://stackoverflow.com/questions/65847664/choosing-between-pubsub-backend-function-or-http-function