Replit Autoscale deployment: database connection pool lifetime during scale-to-zero
0 reputation · 10 Sept 2021, 08:17 UTC
0 reputation · 10 Sept 2021, 08:17 UTC
Replit offers two deployment models: Autoscale deployments that scale to zero on inactivity and cold-start on demand, and Reserved VM (Always On) deployments that keep a process running continuously. Applications using managed PostgreSQL integrations typically configure a connection pool in the application layer.
When an Autoscale deployment scales to zero, the underlying process terminates. It is unclear from current documentation whether pooled database connections are explicitly closed and discarded during that shutdown, or whether the pool is simply abandoned and recreated on the next cold start. The distinction affects pool sizing, connection churn on the database side, and the likelihood of transient exhaustion during rapid scale-up.
Determine the exact connection lifecycle for managed PostgreSQL when an Autoscale deployment transitions from idle to active, so that pool configuration can be matched to the platform's actual behavior.
Does the platform send a termination signal that allows graceful pool drain? Is the pool rebuilt from scratch on each cold start? Are there differences between the built-in key-value store and external PostgreSQL integrations in this regard?
33775 reputation · 10 Sept 2021, 14:20 UTC
In an Autoscale deployment on Replit, the application runs inside a container that is terminated when the instance becomes idle. The connection pool you create in the application lives in that container’s memory; when the process exits, the pool is destroyed. The pool is not persisted across scale‑to‑zero and is rebuilt from scratch on the next cold start. There is no documented graceful drain of the pool – the container simply exits, severing the TCP connections. The same applies to any managed PostgreSQL integration; the key‑value store is platform‑managed and does not use a user‑configured pool.
max_connections or rate limits on the managed database.console.log('app started'))SIGTERM)pool.end() callback)pool = new Pool())pg_stat_activity view around the idle‑to‑active transition to observe abrupt connection drops and new session creations.To refine the recommendation, it would help to know whether your application explicitly handles the termination signal (e.g., SIGTERM) and initiates an orderly pool.end() before the process exits. If you already implement that, you can reduce the abruptness of connection loss, though the pool will still be rebuilt on the next start.
Plan your pool for the maximum concurrent load you expect during normal operation, not for retention across scale‑to‑zero. Avoid a large min pool size; instead, allow the pool to grow on demand. Consider adding a brief pool.end() handler on SIGTERM if you want to give the database a graceful notice, but remember that the pool will be re‑created on the next cold start anyway.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.