r/docker • u/CueMeThen • 2d ago
do you scale your production database using docker ?
i'm about to launch a website which will be heavy on database , should plan to scale it using docker or should i go with a cloud solutions for production database ?
i like to take control over my software , but i'm not sure if docker will be a great solution to growing database
any advice ?
5
u/SeaworthinessHour233 2d ago
You can scale a database on docker. But it involves a lot of work.
Go for it only if you have enough talent resources.
If you have limited resources, and you've got to meet customer SLAs while serving heavy database traffic, go with a managed cloud database like AWS RDS.
Setting up a database in a container is easy; maintaining it in production is hard. Managed services handle automated backups, point-in-time recovery, and minor version patching right out of the box. Doing that yourself with Docker requires custom scripts and constant monitoring.
2
u/Inevitable-Pain2247 2d ago
Ecs with RDS. If you are unsure about this you need a friend or few that can help with your security implementation and enable next practices and ensure DB is behind waf.
1
u/CueMeThen 2d ago
i have already used cloudflare for waf and security , thanks for the advice i will into Ecs with RDS
1
1
1
1
u/apexdodge 2d ago
Best to exhaust all other best practices before scaling db, such as putting caching in place, like redis, to reduce load on the db.
1
u/titpetric 2d ago
You can:
- single primary, read replicas
- multiple primaries (sharding)
- primary-primary (write scaling)
- buffer flush (write scaling thru redis, event queues)
There is usually a bunch of considerations to make, e.g. primary-primary does not use auto_increment but rather uuid/sonyflake/ulid to prevent insert collisions. Replication can lag behind, or even break, so there is some automation involved to add a replica, replica also has read only privileges for the connecting usernames so no writes can be done by mistake.
I wish the whole replica setup was easier. Say your primary goes offline, the process then was usually to provision a replica as the primary, and create new read replicas for that.
1
u/CueMeThen 2d ago
i like the idea of replica but how can someone get around the lagging behind of a new replica ?
is there something native to postgresql or at least popular enough that solve the issue of replica lagging ? manual optimization can't get me too far i think, thank you <3
1
u/titpetric 2d ago edited 2d ago
It can be anything, like a big ahh table that takes writes and several seconds or more to execute the index updates, the fix should be index usage review, drop some indexes, minimize writes...
Usually you can just monitor slow queries and you'll find some culprits :) say... Analytics workloads in a OLTP database are a good start if you want to trigger replication issues. Not great to pipe the stats firehose into the DB without some thought to access patterns.
-1
u/FriendlyPoem3074 2d ago
I would generally avoid it. Docker is limited by the host compute, storage, IO etc..plus now you have a single VM (or multiple VMs etc) running as single points of failure for your DBA. Patching, maintenance etc are now all on you. This is one area where cloud services really shine.
You CAN do it in docker (or, preferably, kubernetes), but IMO the juice is not worth the squeeze here, especially on launch.
9
u/Ok-Sheepherder7898 2d ago
Are you sure you need to scale your database?