Skip to content
Tutorials Center
My learning

Topics

Lesson 105 of 125 ยท Database Systems

Where to Host a SQL Database

Compare SQL hosting options: on-premises, VPS, shared hosting, managed cloud databases and serverless. Trade-offs in cost, backups, scaling and compliance.

Writing SQL is only half the job. Sooner or later your database has to live somewhere: on a machine that stays on, has enough disk, gets backed up, accepts connections from your application and does not fall over at 3 a.m. The place you choose decides your monthly bill, how much operations work lands on you, how far you can scale, and where your customers' data legally resides.

There is no single best answer. A weekend project, a startup's first product and a bank's core ledger should be hosted differently. This lesson lays out the realistic options, the trade-offs between them, and a short checklist for choosing, so you can make the decision on purpose instead of by accident.

The five common options

1. A file next to your application (embedded)

SQLite is a database in a single file. There is no server to host at all: your application opens the file directly. It is excellent for mobile apps, desktop tools, small sites, tests and prototypes, and surprisingly capable for read-heavy websites. The limits are the ones from Isolation Levels and Locking: one writer at a time, and the file must be on a disk the application process can reach. You cannot easily share it between several application servers.

2. Shared hosting

Cheap web hosting plans often include a MySQL or MariaDB database, managed through a control panel such as cPanel or phpMyAdmin. You get a database name, a user and a password, and nothing more.

  • Good for: small websites, blogs, a first learning project.
  • Limits: you share a server with strangers, you cannot install extensions or change server settings, connection counts and query time are capped, and remote connections are often blocked.

3. A virtual private server (VPS) or your own machine

You rent a Linux virtual machine (or run a server in your office or data center, which is called on-premises) and install PostgreSQL, MySQL or SQL Server yourself. You have complete control over versions, extensions, configuration and file layout.

  • Good for: teams with operations skills, special requirements (a particular extension or version), predictable steady load, and tight budgets at moderate scale.
  • The catch: everything is your job. Security patches, backups, restore tests, monitoring, replication, failover, disk growth and tuning all belong to you. Most outages here are caused by a full disk, a missed backup or an unpatched server, not by clever attacks.

4. Managed cloud database (DBaaS)

A cloud provider runs the database server for you: Amazon RDS and Aurora, Google Cloud SQL, Azure SQL Database and the managed offerings of Neon, Supabase, PlanetScale, DigitalOcean and many others. You pick an engine, a size and a region, and you receive a connection string.

The provider handles operating system and engine patching, automated backups with point-in-time recovery, standby replicas with automatic failover, and monitoring dashboards. You still own your schema, indexes, queries and users.

  • Good for: most production applications. It removes the least interesting and most dangerous operations work.
  • Costs and limits: you pay for the convenience. Superuser access and some extensions or settings are restricted, and moving away later takes effort because of provider-specific features. Data transfer ("egress") out of the provider is often billed.

5. Serverless databases

Serverless offerings (for example Aurora Serverless, Neon, PlanetScale, Cloudflare D1, Turso, or Azure SQL serverless tier) scale compute up and down automatically, and may pause completely when idle. You pay for what you use.

  • Good for: spiky or unpredictable traffic, development and preview environments, many small databases (one per customer or per branch).
  • Watch for: cold starts after a pause (the first query can be slow), connection limits (serverless functions can open thousands of short connections, so you may need a pooler, see Plan Cache and Connection Pooling), and a bill that can surprise you under sustained heavy load.

How much data will you actually have?

Many people over-plan. Before choosing, estimate your size. In this sandbox you can ask SQLite how big a database is:

SQL How big is this database? ยท database: shop

Press Run (or Ctrl + Enter) to see the result here.

A shop with thousands of orders fits in kilobytes to a few megabytes. Even a million orders is typically a few hundred megabytes with indexes. The size is usually not what pushes you off a small server; traffic, memory and the quality of your queries are. In PostgreSQL the equivalent is SELECT pg_size_pretty(pg_database_size(current_database()));, and in MySQL you can sum data_length + index_length from information_schema.tables.

A rough cost model also helps. The numbers below are invented for illustration only, so substitute real prices from the providers you are comparing:

SQL A simple monthly cost model (made-up prices)

Press Run (or Ctrl + Enter) to see the result here.

The point is the last two columns: the cheapest invoice is often not the cheapest total, because your own operations time costs money too. For a team with no database specialist, a managed service usually wins even at a higher sticker price.

Questions that decide the choice

Availability. What happens if the database is down for an hour? A single VPS has no automatic failover. Managed services offer a standby in another availability zone, typically for roughly double the price. Write down the downtime you can tolerate.

Backups and recovery. Ask two questions, not one: how much data can you lose (RPO) and how fast must you be back (RTO)? Whatever you choose, test restoring a backup. See Backup and Maintenance.

Scaling. Most databases scale up easily (bigger machine) and out for reads with replicas, as in Replication and Scaling. Scaling writes beyond one machine is hard everywhere. Pick a provider where the next size up is one click, so growth is a configuration change, not a migration project.

Latency. Put the database in the same region, ideally the same zone, as the application. A query that takes 1 ms inside a data center takes 80 ms across an ocean, and a page that runs 30 queries turns that into seconds. This is the most common reason a "fast" cloud database feels slow.

Security. Prefer private networking or an allow-list of IP addresses over a database open to the whole internet. Require TLS, use separate users with minimal rights (Users and Permissions), and keep secrets out of source code. Check whether you can encrypt data at rest (Encryption).

Compliance and data residency. Laws such as the GDPR, and industry rules for health and payment data, can restrict where personal data may be stored and who may operate the servers. Choose the region on purpose, and check the provider's certifications (for example SOC 2, ISO 27001, HIPAA eligibility) if your industry needs them.

Lock-in. Standard engines (PostgreSQL, MySQL) hosted anywhere are easy to move with a dump and restore. Proprietary variants and provider-specific features make leaving harder. Decide how much you value portability.

Cost surprises. Look for charges beyond the instance: storage and provisioned IOPS, backup retention, data transfer out, replicas, and idle resources you forgot to delete.

A sensible path for most projects

  1. Learn and prototype: SQLite, or a local database in Docker.
  2. First real deployment: a small managed PostgreSQL or MySQL instance in the same region as your app, with automated backups switched on.
  3. Growth: scale the instance up, add a read replica for reports (Designing a Database for Real-Time Reporting), add connection pooling, tune slow queries.
  4. Special needs: move to self-managed servers or a dedicated platform only when you have a concrete reason (cost at scale, a required extension, regulatory control) and the people to run it.

Choose an engine whose behavior you understand (PostgreSQL, MySQL, SQL Server and Oracle), and keep your SQL as portable as you reasonably can (SQL Dialects). Hosting choices change; a well-designed schema moves with you.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which hosting option puts the most operations work (patching, backups, failover) on your own team?

    On a VPS or your own hardware you install and run the database yourself, so patching, backups, monitoring and failover are all your responsibility.
  2. 2. Why can a database in a different region make an application feel slow even when the queries are fast?

    Network latency is added to every query. Thirty queries at 80 ms each is more than two seconds, even if the database itself answers in a millisecond.
  3. 3. What is a common issue to plan for with serverless databases?

    Paused databases need a moment to wake up, and bursts of short connections can exhaust connection limits, so a pooler is often needed.
  4. 4. Which pair of measures describes how much data you can lose and how quickly you must recover?

    Recovery point objective (RPO) is the acceptable data loss; recovery time objective (RTO) is the acceptable downtime.
  5. 5. Besides the monthly instance price, which of these is a common source of surprise cloud database costs?

    Storage, provisioned IOPS, backups, replicas and data leaving the provider are billed separately and can add up.

Summary

  • Options range from an embedded SQLite file, shared hosting and self-managed servers to managed cloud databases and serverless.
  • Managed services remove most operations work; self-managing gives control but makes you responsible for patches, backups and failover.
  • Serverless suits spiky load, but plan for cold starts, connection limits and usage-based bills.
  • Estimate size before you over-plan; traffic and query quality usually matter more than raw data volume.
  • Decide on availability (RPO, RTO), latency (same region as the app), security, compliance and data residency, lock-in and hidden costs.
  • A sensible path: SQLite to learn, a small managed database in production, then replicas, pooling and tuning as you grow.

Next: Geospatial SQL, where you'll store and query locations and distances.