A managed database refuses new connections once its limit is reached, well before it saturates, and it is often reachable from the Internet until you close it. This lesson covers these two common configuration flaws: how to spread the applications' connections towards the database, and how to reach the database over the private network. It is aimed at intermediate-level readers who already know a private network; the notion of a connection pool is defined in the lesson.
What you will learn
- Explain why a lightly loaded database refuses connections.
- Choose a connection pooler rather than a bigger instance.
- Close the public access of a managed database and go through the private network.
- Verify isolation through the provider's setting, then through a test from outside.
To follow this lesson, first read Managed data: databases, caches and queues in the cloud, and know what a private subnet is (see the networking course (in French)).
Why does the database refuse new connections?
The number of simultaneous connections of a managed database is capped, and the cap depends on the size of the instance. It is a limit you hit well before saturating the processor, and its symptom looks like a general outage: the application can no longer connect, while the database is lightly loaded.
A connection pool is a small stock of already open connections that the application reuses instead of opening a new one for each request. Each application maintains its own, which is efficient for that application alone, but the database's limit counts the sum of all the pools. Two modern developments bring this wall much closer than before:
- Autoscaling (adding and removing machines according to the load, without intervention). Each application machine added opens its own batch of connections. Twenty machines with a pool of twenty connections ask for four hundred, and the limit of a small instance is often lower.
- Serverless functions. Each concurrent execution may open its own connection, with no possible sharing between them. A hundred simultaneous executions exhaust the limit in a few seconds.
The answer is not to enlarge the instance, but to insert a connection pooler. This component keeps a small number of connections really open towards the database and lends them to the clients. Providers offer their managed version, and equivalent open source projects have existed for a long time for PostgreSQL and MySQL. Enlarging the instance moves the wall by a few hundred connections and multiplies the bill; the pooler fixes the problem for a fraction of the price.
How do you reach a managed database without going through the Internet?
A managed database is often reachable through a public address (a name or an IP, depending on the provider): check the default setting of yours and correct it. The service listens behind a firewall that only allows your addresses, but the network path itself goes through the outside: your traffic leaves, transits, comes back, and is billed along the way.
Two complementary settings close this door:
- Disable public accessibility of the instance, so that it only has an address in your private network. It is the most important setting: set it at creation, then verify it with the proof of state below.
- Go through a private endpoint, that is, an address that belongs to your private network and leads to a provider service without crossing the Internet, for provider services that have no address in your network. This removes along the way the traffic billed by the NAT gateway, through which it would otherwise pass. The mechanism and its effect on the bill are detailed in the lesson Private endpoint: reach a managed service without the Internet (in French).
Check the result rather than assuming it, with two proofs that do not say the same thing. The proof of state reads the provider's setting: it is the only one that is authoritative. The proof of behaviour tests the network from outside and complements it. A test run from inside your network proves nothing: on AWS, the name of a public database resolves to the private address from within the VPC (AWS's virtual private network), and to the public address from outside only.
Proof of state on AWS. The PubliclyAccessible field of each instance must be false.
aws rds describe-db-instances --query 'DBInstances[].PubliclyAccessible'The output is a list of booleans, one per instance: a single true value points to an exposed database. This setting determines whether the name of the instance resolves to a public address; access is, in addition, filtered by the security group.
Proof of state on Scaleway. An endpoint is the address and port through which the instance is reached. A public endpoint carries a load_balancer key, a private endpoint a private_network key. The scw rdb endpoint list <instance-id> command only displays the ID, IP, PORT, NAME and HOSTNAME columns, without a type: a private IP (RFC 1918 range, 172.16.x.x by default) means private, a public IP means public. To read the type, ask for the JSON.
scw rdb endpoint list <instance-id>scw rdb instance get <instance-id> -o json | jq '.endpoints[] | keys'The second command lists, for each endpoint, its keys. The expected proof of state: no more entries with load_balancer, only entries with private_network. The name field is null and hostname is absent: the public endpoint is an IP and a port, not a name.
To add a private endpoint, create a Private Network, then scw rdb endpoint create <instance-id> private-network.private-network-id=<pn-id>. To remove the public endpoint, use scw rdb endpoint delete <endpoint-id> instance-id=<instance-id>. The instance then briefly goes to the configuring state (of the order of ten seconds on an empty instance, a duration that varies) before returning to ready: this is the reset announced by Scaleway. According to its documentation, a public endpoint recreated afterwards receives a new IPv4 and a new port.
An allowed-address list (ACL) on a public endpoint restricts it without removing it: this is not the same as "not reachable".
Proof of behaviour. From a machine outside your network (your workstation, off the VPN, or a machine from another provider), try to open the port. On AWS, first ask a public resolver what the name becomes, for the A (IPv4) and AAAA (IPv6) records.
dig +short <database-name> A @9.9.9.9dig +short <database-name> AAAA @9.9.9.9nc -vz -w 5 <name-or-ip> <port>On AWS, the first two commands must return no routable public address: nothing, or an address in a private range (10.x.x.x, 172.16.x.x to 172.31.x.x, 192.168.x.x). Write the criterion this way, and not "no answer", because AWS documentation does not specify what a public resolver returns for a private instance. The third tries to open the port (5432 by default for PostgreSQL) with a maximum wait of 5 seconds.
On Scaleway, there is no name to query: dig +short <ip> A on an IP returns nothing (this is normal, an IP has no A record), and neither does AAAA. Go straight to nc with the IP and the port of the endpoint (a high port, for example 16054, not 5432). As long as the public endpoint exists, the command answers succeeded. Once the endpoint is removed, the same nc to the old IP and the old port answered Connection refused during the test run of 12 October 2026; a released IP may be reassigned, so this test remains a complement, and the proof of state is authoritative.
Read the result with caution. A timeout means "packets ignored": no route, or a filter that silently drops. It therefore proves nothing on its own. A refusal (Connection refused) indicates that the machine is reached but the service is not listening, or that a firewall answers no. Conversely, a public address that answers dig does not prove the port is open, because a security group may filter. Finally, an nc to a 10.x address run from outside may hit the tester's local network: check that the address does not belong to your own network before concluding.
Put it into practice
This lab brings together the first three lessons of the module (the fourth, on PostgreSQL, comes after): managed or self-managed service, protecting the database, private access. It gives the brief of a transactional workload and a synthetic catalogue of data services. You write data-service-decision.json: the chosen service, access through a private endpoint, replication, the recovery objectives (RPO and RTO), point-in-time recovery, and who verifies a restore, with a reason for each option ruled out. The validation rereads the catalogue: the service must meet all the constraints and the access must be private, with no exposure to the Internet. It is an architecture decision, with no deployment and no real failover.
Key points
- The connection limit is reached before the processor saturates. A connection pooler fixes the problem, enlarging the instance only moves it.
- Autoscaling and serverless functions multiply connections: twenty machines at twenty connections ask for four hundred.
- A managed database is often public by default, depending on the provider: check the setting and turn off public accessibility at creation.
- A private endpoint leads to a provider service without crossing the Internet.
- Verify with two proofs: the state (
PubliclyAccessibleset tofalseon AWS, noload_balancerendpoint inscw rdb instance get -o jsonon Scaleway) is authoritative; the behaviour (nc, preceded bydigon AWS, from outside) complements it. A timeout alone proves nothing.
Knowledge check
Check that you have grasped the essentials of this guide. The questions cover only what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: IAM: manage identities and permissions in the cloud
A new full quiz with random questions
Work again only on the questions you missed