There are lots of interesting new databases that have features for this, try them out! Long lived connections Truly write-heavy apps require latency aware data partitioning, either at the app level or in a database engine. If you’re running an application like this, you should consider using something like nats.io to send information to your primary region asynchronously. Some apps write background info like metrics or audit logs on every request, but are otherwise read heavy. You will need to make some architectural changes to run a write-heavy app in multiple regions. If you write to the database on every request, this will not work for you. That is, most requests only perform reads and only some requests include writes. We built this set of features for read heavy apps that are primary HTTP request based. This probably won’t work well for far flung read replicas. In theory, you could run PostgreSQL with synchronous replication and block until replicas receive writes. When the user makes a request and the session’s data version differs from the replica, you can use the same fly-replay header to redirect their request to the primary region – and then you’ll know it’s not stale. Managing eventual consistencyįor apps that are sensitive to consistency issues, you can add a counter or timestamp to user sessions that indicates what “version” of the database a particular user is expecting. If your app is sensitive to this (meaning, you never, under any circumstances want to show users stale data), you should be careful using read replicas. A lagging read replica might result in an out of date view for users, but this might be reasonable for your use case. Most read heavy applications aren’t especially sensitive to stale data on subsequent requests. In most cases, the database will replicate the changes before the user makes the second request. Most apps accept a POST or PUT, do a bunch of writes, and then redirect the user to a GET request. Your application will behave like you expect. When you use the replay header to target a particular region, the entire request runs against the leader database. Requests to the primary region are strongly consistent. Running read replicas across the world can exacerbate this effect and make read replicas stale more frequently. Read replicas are usually eventually consistent, and can fall behind the leader. This is a fairly typical read replica model. If you have a particular app you’d like to distribute with PostgreSQL, post in our community forums and we’ll write some code for you. We would like to build libraries to make this seamless for most application frameworks and runtimes. headers = "region= # ", status: 409 else raise e end end end Library support is_a? ( PG :: ReadOnlySqlTransaction ) r = ENV response.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |