Handling instance-level cleanup in Vercel Functions vs AWS Lambda
The following problem has been bugging me for a while, I'm curious how others are approaching it.
In serverless enviornments, the general recommendation is to have one runtime per instance, instead of one runtime per request. Especially with db connection pooling and logging/telemetry/analytics services.
When an instance terminates, we need to dispose of the runtime (e.g. closing db connections, flushing logs). This can be achieved in AWS Lambda by listening for
SIGTERM
SIGTERM
.
However, Vercel Functions currently offers graceful shutdown only at the request level via
waitUntil
waitUntil
. This means there's no way to dispose of instance-level runtimes.