Note to Self: MongoDB can be used with serverless functions by caching the initial connection.
database engines were designed much before the serverless architecture was a thing.
a connection to the database is always persistent. meaning, it lasts for a really long time.
also, there is a limit(imposed by DBaaS provider) on how many connections a database can have at any given timestamp.
a lambda function is invoked every time a client(generally, browsers) creates a connection. this means a new connection to the database as well.
this, in turn, would reach the connection quota really soon.
having a cache connection to database helps up to some extent. simply store an existing connection in a variable..and reuse it whenever you need to connect to the database.
a better way is: having a proxy DB server sitting in front of the actual database server.
this way, one persistent connection would be made to the database(by that proxy)..and serverless functions can connect to the proxy server as and when needed.
you can also abstract all database operations into a separate server and let the
serverless functions communicate with that through a RESTful API :)
caching is the process of storing data temporarily. a cache generally lives for a relatively small amount of time. examples: browser cache, DNS caching etc.
* save bandwidth (and reuse resources)
when using cache mechanism in client-side applications, it ensures that cached files won't be downloaded again from the server.
* save processing power
when writing algorithms, it could be optimized using a caching mechanism...
2/n
...caching would help add memorization to that algorithm, enabling it NOT to repeat the same calculations again and again.
* save time
we all visit websites mostly by domain names(and rarely using the IP address). having cached DNS records would let the resolver use...
3/n
it is a type of attack performed on web apps in order to carry out a malicious action without user's explicit consent.
these 'malicious actions' could be anything. for example: changing email address, personal information etc