What awakes compute?

The main question is. Let say I have an app, that is just a Node.js app that always runs in fargate cluster.
It makes a connection to the Neon. And, I suppose it holds this connection all the time (I use Drizzle). Will that keep instance alive all this time?

Same question to connection pools that one of my 3rd party self hosted service uses. They’re using typical for Java Hikari pool always keeping 10 connections open.

The problem is that I think it really keeps them alive as far as I can tell and really angry when connections are getting closed reopening them if I understand it correctly making Neon to wake up.

Failed to validate connection org.postgresql.jdbc.PgConnection@5ba4e963 (This connection has been closed.). Possibly consider using a shorter maxLifetime value.

For production instance I wouldn’t bother, but for development instances I’m concerned as it suppose to be cheap and nearly 0 cost, but ends up being easily the same cost as Postgres that is permanently hosted on AWS let say. So around 13$ for single AZ micro instance (which is 1 vCPU and not 0.25 vCPU)

So the question is. Can you explain in detail how connections affect the Idle/Active state. And what is the best approach to avoid excessive activation of the Neon computes.

I thought that a constant connection from the instance shouldn’t keep the compute alive (I mean, via some magic, as, I think, some compute needed for that), but only actual queries. And in that case that would be an amazing saving, or at least same cost, but so much more features. But now I see that maybe it’s not worth it.

Any new connection wakes up Compute. Right now, after 5 minutes of inactivity on all connections (if any) we will shut Compute down, but if you then reconnect that will wake compute again.

The best plan for test applications is to set the minimum connection pool size to 0, and to make sure the pool size actually shrinks to zero when not in use. Alternatively, you could shut down the applications completely while not in use.

And when instance is shot down, connection is closed. Is client e.g. my server, gets notified of that somehow?
Sorry, concept of “connection” for me is rather unknown :slight_smile: Like is it just confirmed TCP/IP handshake, info about which is hold in memory as proven to be real? I don’t understand if compute should be alive for connection to stay. And what “connection to stay” is even means? Constant ping back and forth?

UPD:
Don’t really need to explain. I asked ChatCPT and I think I’ve got a very detailed response :slight_smile:
In super short it’s TCP/IP handshake + generation of a session that both kept in client AND database. And opening a connection is basically get to know each other AND record that there is a client with such credentials and generate a session for it to quickly figure out authorised or not.
If compute is killed, session on DB layer gets killed with its memory, so effectively connection on a client side becomes stale even tho it may still be “open” (if DB is not notifying clients about the expiration), so next time DB client makes a request he’ll have to invalidate old and create new connection.

Unless you have some sort of layered structure there, like some pooler, then bunch of computes and then storage.
And pooler being awake all the time keeping connection alive, then I think sleeping compute = no active connections, no matter, there are queries on connection, or not, if there is an active connection, DB is not sleeping. If it was inactive for some time, then it will proactively close connection and go to sleep.

Let me know if I understood it correctly.