Why PostgreSQL High Availability Matters and How to Achieve It
yugabyte.com
yugabyte.com
Unfortunately Spanner isn’t open source. Yugabyte and Citus are close but have annoying issues. Cockroach isn’t 100% compatible (and has its own issues) and things like FoundationDB which are truly HA and comparable to Spanner in terms of consistency and fault tolerance are not easily plugged into Postgres as the underlying storage engine since sadly it’s only a key value store.
edit: when I say close, I'm talking strictly about HA, not general functionality.
lately I've been thinking of using FoundationDB, which is closest to Spanner in terms of ACID and serializability and mvsqlite.
Then, I was thinking, since SQLite doesn't have online schema changes (nor does mvsqlite) to have a schema such as:
[UUID, Data, Version, CreatedAt, UpdatedAt]
Where Data is a JSON or Proto and Version is an integer. You then could mimic an online schema change by in your application code supporting two adjacent "versions", and then in an eventually consistent manner run [small] transactions to update the Data to the new Version as necessary. You would index Version, and UpdatedAt as necessary to find the rows in the table that are not "migrated."In SQLite you can also create indexes on expressions so technically all of your JSON or Proto could also have indexes.
If I were building a new startup in 2023, I would need a mountain of evidence against using Spanner. It's ugly that it locks you into GCP but hey an iPhone locks you into Apple's ecosystem, that's just the price you pay to get good things.
* unless you need timeseries, columnar, FTS, geospatial, graph or something special like that
So yeah, I'd rather spend a few more hours picking an actual scalable technology now than spend what could be 7 figures (it can be a lot more, I've heard of this migration uber had to do that was costing them half a billion a year) and massively impact product development moving to scalable technology..
But sharding is too use-case specific to prescribe something broadly like Spanner.
Here's the problem, it's not 90%. Idk about those two, but you sacrifice a lot using Spanner, maybe enough to delay your launch. Any slightly advanced query becomes hard to optimize, for one. Not to dis Spanner, it's just a very different beast.
CEO won't want to hear "launch is delayed, but it'll scale better later," and it's also not really true. In the initial phases, you can't tell what your actual needs will be at scale, so you'll probably have to rework things anyway. Just using Spanner doesn't solve your scaling problems. Maybe you'll need to totally redo your Spanner schema to actually scale, maybe you find you're better off sharding at the application layer than at the DB.
Spanner is very expensive even compared to hosted cockroach and RDS (Aurora). That being said I’m sure if you're enterprise it's substantially cheaper.
Spanner generally is about twice the cost as cockroach which seems cheap but the gap in nominal cost only grows with usage.
The other issue is that since there’s no source to self host you also have to pay, unlike cockroach.
Generally with cockroach I’d expect one to self host all instances except a staging/pre-pod and prod. With Spanner all your instances necessarily will be hosted, which means $$.
That being all said, Spanner is worth it if money isn’t an issue
Back of napkin math I did a couple of months ago: Spanner costs about $1/month for 2 writes/second and 10 reads/second. The minimum is $88 which is 176wps and 880rps. If your startup gets more traffic than that, you have good problems. The simplified guarantee model (fully linearizable and serializable everything; automagic sharding, replication and failover) could save you costs elsewhere.
Low-value high-volume data like logs and search queries can be sent to a cheaper self-hosted timeseries/fts database.
Doesn't spanner introduce new (very unlikely) failure modes that other databases are not impacted by? The reliance on an external consistency model feels to me like a complete outsourcing of liability that warrants thorough investigation.
Hypothetically, if GPS went down for a prolonged period and/or a bug was found in the TrueTime system, what would happen to the consistency model around Spanner?
I feel like some applications and customers would much rather wait for a synchronous acknowledgement from the actual, live system. An extra 150ms when you are confirming a 6-figure wire transfer could easily be framed as a good thing in most circles.
>Doesn't spanner introduce new (very unlikely) failure modes that other databases are not impacted by?
Curious if you could go into that.
As I understand it, it's not a solved problem because there is no silver bullet, but rather trade-offs in every direction, and which solution works for you (including Spanner) is heavily dependent on your use case.
the clocks remove such limitations.
When you get into sharded DBs, a lot of limitations aren't obvious at first. I've used Citus a long time ago and Spanner much more recently. Spanner feels almost like NoSQL: Each table is like a distributed KV store. Indexes are just tables where the PK is the indexed col(s) and the val is the main table's PK, though you can also store additional cols (aka denormalize) in the index to avoid an extra join. You can't combine two indexes to filter on two cols; you need one composite index. More advanced things like order-limit, WHERE (NOT) IN, and subqueries tend to be slow. The query planner is pretty limited, and often I just force things. You also have to really know what you're doing with the pkeys. Which is all understandable, given its requirements.
I forget the limitations of Citus ACID, but they're significant. Spanner has full ACID, but even basic operations are quite slow. Single-node Postgres actually doesn't have full ACID unless you put it in the slower SERIALIZABLE mode, but you don't really need it.
I agree with those who say it's better to focus on sharding at the application layer if possible. If you can't do that, it's probably due to the underlying nature of your problem, in which case sharding at the DB layer in an efficient way tends to be even harder. Sometimes it makes sense, but it's not magic.
Can you expand on how you perceive traditional RDMSs to be different for this case?
CREATE TABLE foo (id bigserial, bar int, baz int);
CREATE INDEX foobar ON foo(bar);
CREATE INDEX foobaz ON foo(baz);
SELECT \* FROM foo WHERE bar = 2 AND baz = 4;
Postgres (and I think MySQL) will use both indexes in the above query*. Spanner can only use one index, which will be slow if there are many non-matching bar=2 or baz=4 rows.So Spanner needs CREATE INDEX foobarbaz ON foo(bar, baz); Which Postgres could also use, and it'd be a bit faster, but the index-combining is decently fast too and much nicer when you consider a table with like 10 cols and many ways to filter/join.
* https://www.postgresql.org/docs/current/indexes-bitmap-scans...
Serializable mode uses some kind of optimistic concurrency, where your transaction might get halfway through then fail because of a conflict with another one, which also fails. Then you have to do retry + random backoff on the client side. Spanner does something similar. Problem with Postgres serializable mode is it's slow and won't scale well if many readers/writers are touching the same data.
I get it if this answer isn't satisfying. Partial ACID is worrisome, and full ACID is expensive.
or for k8s their operator: https://github.com/zalando/postgres-operator (docker image: https://github.com/zalando/spilo) we've also tried other operators which were easier to get started, but they failed miserably (crunchyrolls operator is basically based on the zalando one)
Patroni has great docs for this here: https://patroni.readthedocs.io/en/latest/replication_modes.h... (Actually this is more or less a thing to do with Postgres)
Granted, we might've messed something up and there are lots of factors, but you should manually check your individual nodes every so often to make sure none of them are going out of sync. Need to connect to each one directly, can't rely on what the bouncer/pgpool/loadbalancer is showing you to check the data is the same. It happened repeatedly to us, and wasn't obvious from any of our monitoring. In the end we had to scale down to 1 node while we sort out moving to a different operator.
[0] https://opensource.google/documentation/reference/using/agpl...
https://blogs.microsoft.com/blog/2019/01/24/microsoft-acquir...
The license allows you to do many things, but not everything.
The copyright owner on the other had, can do everything.
That’s why many projects nowadays require you to assign copyright to the team before accepting a contribution.
denoting software for which the original source code is made freely available and may be redistributed and modified.
> agpl limitations
The AGPL License does not permit sublicensing of the code; that is, you cannot rework or add to the code and then close those changes off to the public.
considering these facts, your opinion is honestly ... pretty dumb.
There is nothing hard about forking the repository and then creating a readonly mirror of your working copy on a public github repo.
> denoting software for which the original source code is made freely available and may be redistributed and modified.
Being honest, I didn't examine the OSD closely when writing the comment, but I still feel AGPL might violate rule #10 for the open source criterion.[0]
However, it's much more clear cut going over to the free software side.[1] Specifically, the explanatory text in the free software philosophy states: "The freedom to run the program means the freedom for any kind of person or organization to use it on any kind of computer system, for any kind of overall job and purpose, without being required to communicate about it with the developer or any other specific entity."
The AGPL requires that you communicate your use of the software, and further forces you to provide access to the source code. For unmodified copies, it might be sufficient to link back to an upstream project. As soon as you modify even a single line, you must now provide your own fork, which will involve setting up some sort of infrastructure. That's assuming that the source code still exists (you might be surprised how often it's lost).
> considering these facts, your opinion is honestly ... pretty dumb.
100% disagree :)
[0] https://opensource.org/osd/ [1] https://www.gnu.org/philosophy/free-sw.html
https://learn.microsoft.com/en-us/sql/sql-server/failover-cl...
https://learn.microsoft.com/en-us/azure/azure-sql/database/s...
I looked at Planetscale thinking I might be willing to just use MySQL, but even if I were to take a risk with their confusing pricing it turns out there are no foreign keys.
And there is no equivalent of Cloud run on AWS.
It just seems like there is a gap here in when it comes to managed databases, not just GCP laking any kind of "free tier" option, but just a lack of players in the space between free and established business pricing for HA.
Use serverless cockroachdb. Yugabyte also has a free tier. As does Fauna and Planetscale.
Make your life easy, tons of applications are running for years even without (good) backups
I've been runnning it for over 3 years with great success, and 0 downtime. Not to mention the extreme price difference compared to managed solutions - https://github.com/hapostgres/pg_auto_failover/discussions/6...
But major upgrades are only available once a year.
that's WHY you need at least a multi-region HA database for your apps
(Maybe if I had used IAM auth for the database it wouldn't have?)