3

I just did some reading about serverless computing and FaaS. If using FaaS to access an arbitrary database, we need each time to establish and close a database connection. In, lets say a node applications, we would usually establish the connection once and reuse it for multiple requests.

Correct?

I have a hosted MongoDB at mlab and thought about implementing a REST API with Googles Cloud Functions Service. Don't know how to handle the database connection efficient.

For sure thing get clearer while coding and testing. But I would like to know chances to succeed before spending a lot of time.

Thanks Stefan

Stefan
  • 576
  • 7
  • 27

1 Answers1

1

Serverless platforms reuse the underlying containers between distinct function invocations whenever possible. Hence you can set up a database connection pool in the global function scope and reuse it for subsequent invocations - as long as the container stays warm. GCP has a guide here using MySQL but I imagine the same applies to MongoDB.

Aleksi
  • 4,483
  • 33
  • 45