3 ms·
Ask HN: How do you handle global web scale?
My company has web app users all over the world. They collaborate in real-time, and the app is very write-heavy.
Latency became a huge issue for database writes. The solution we came up with was to split up the app -- multiple regions with their own master database (no syncing cross-regions) and subdomain (e.g. africa.mywebsite.com).
This is working well. There is no concern that there will be any cross-region collaboration between users (at least for now). But it feels like a hack. I want everyone to just be able to go to app.mywebsite.com regardless of region.
There has to be a better way. What strategies are other companies using to solve latency across the globe?
- rtcoms 5y agoHave you looked at Fly.io ? https://fly.io/docs/introduction/ https://fly.io/docs/introduction/
- throaway_pirate 5y agoI have! However, (correct me if I'm wrong) they don't solve the database issue. You still have a single region with a "leader", and other regions just have read-replicas.
- verdverm 5y agoGoogle Cloud Spanner is a SQL database for this problem. There is an open source version iirc, forget the name
- throaway_pirate 5y agoWow this looks awesome! This could definitely be what I'm looking for. Thanks so much!
- plmpsu 5y agoCockroachDB
- mrkurt 5y agoYou're not wrong, but most global databases work exactly like this. They just let you assign ranges of data to leaders, rather than doing it DB by DB. Shopify uses exactly the same model we (Fly.io) do, it's a slightly more evolved version of what you're doing. They run leaders in multiple regions with read replicas scattered around, and then assign the most appropriate leader region to a store. CockroachDB and Spanner let you move ranges of data to different "leaders" within the cluster. If you model your schema well, they work great. But you do have to worry that queries aren't spanning regions or you end up making everything slow. The Fly.io magic is the proxy layer that replays entire HTTP requests to the leader region. It works surprisingly well. If your databases is even close to half reads and half writes, something similar may work nicely.
- mmerlin 5y agoMaybe consider Planetscale / Vitess
- _448 5y agoIf you can change your DB, then Apache CouchDB[0] handles this out of the box. Otherwise consider something like Apace ShardingSphere[1]. [0] https://couchdb.apache.org https://couchdb.apache.org [1] https://shardingsphere.apache.org https://shardingsphere.apache.org
- taf2 5y agoSpeed of light is unfortunately one of the main reasons to do region specific databases… you might be able to do it globally with some sort of clever UI to smooth out the effect of delay and maybe a kind of event stream ordering actions by time… but all depends on the purpose of the writes and how those writes impact other users…
- toast0 5y ago(simple) databases per region is a good solution. If you want to make it work in a single domain, you can do things like put frontend servers with the databases, and more widely distributed proxies that send to the right frontend depending on the user/document/whatever. Or you can do a frontend/backend 'multi-tier' architecture and send requests to the proper backend.