For clarification, when I say "FaaS" I am referring to serverless offerings such as AWS Lambda and Google Cloud Functions.
I have a specific case in mind that I'll describe but I would very much like to hear about any guiding principles in this area as well.
I have a Google Cloud Function that is currently doing some image processing. The flow looks like this:
- JSON file containing several base64 encoded images is uploaded to storage bucket
- Cloud Fucntion downloads file
- Converts and merges all base64 strings into image file
- Uploads image file to storage bucket
- Calls Google Cloud Vision API once file is uploaded
This works, but it has me wondering: how much should a single function do? Most discussions I see regarding single purpose vs. monolithic functions are centered around monolithic functions having logic branches e.g. "if-else". In the above case, this is an example of doing a lot, but, it's conceptually a single unit of "work".
Were I to refactor this into true single purpose functions, I imagine I'd have two functions -- one for downloading and merging images and the other for calling the Vision API. This splits what I consider "image processing" into two sub-units. I have no problem doing this but I'm curious to know whats a good rule-of-thumb for "splitting" FaaS function?
Edit: if anyone is wondering why the image file gets uploaded back into a storage bucket and then the Vision API is called, this due to a limitation of that API where inputs can only be storage bucket URIs and not local files