How PlanetScale Boost serves SQL queries faster
planetscale.com
planetscale.com
I'm so excited to see dynamic, partially-stateful data-flow for incremental materialized view maintenance becoming more wide-spread! I continue to think it's a _great_ idea, and the speed-ups (and complexity reduction) it can yield are pretty immense, so seeing more folks building on the idea makes me very happy.
The PlanetScale blog post references my original "Noria" OSDI paper (https://pdos.csail.mit.edu/papers/noria:osdi18.pdf), but I'd actually recommend my PhD thesis instead (https://jon.thesquareplanet.com/papers/phd-thesis.pdf), as it goes much deeper about some of the technical challenges and solutions involved. It also has a chapter (Appendix A) that covers how it all works by analogy, which the less-technical among the audience may appreciate :) A recording of my thesis defense on this, which may be more digestible than the thesis itself, is also online at https://www.youtube.com/watch?v=GctxvSPIfr8, as well as a shorter talk from a few years earlier at https://www.youtube.com/watch?v=s19G6n0UjsM. And the Noria research prototype (written in Rust) is on GitHub: https://github.com/mit-pdos/noria.
As others have already mentioned in the comments, I co-founded ReadySet (https://readyset.io/) shortly after graduating specifically to build off of Noria, and they're doing amazing work to provide these kinds of speed-ups for general-purpose relational databases. If you're using one of those, it's worth giving ReadySet a look to get these kinds of speedups there! It's also source-available @ https://github.com/readysettech/readyset if you're curious.
I already had Naiad on my reading list, definitely adding Noria as well! Thank you very much for your work!
If you're reading this announcement post and want to play around with instant query caching àla Noria in your existing Postgres or MySQL database, shoot me a me an email and we'll bump you up on our cloud waitlist :) alana@readyset.io
You can get connected today in a few minutes, without code or configuration. PolyScale supports Postgres, MySQL, MariaDB and SQL Server, with GraphQL with others coming soon. You can also try the live demo [2].
[1] https://www.polyscale.ai/ [2] https://playground.polyscale.ai/
Traditionally, other materialized view implementations have very strict query requirements though. The queries had to be deterministic. No left joins, dates, etc. This is required in order to properly detect when data changes "impact" the view. I wonder how they get around it.
Update: Ah, ok! Here's a write up on how it works a bit. My last startup built a system like this specifically to power a gamification engine. Would have been nice to have this 10 years ago.
https://planetscale.com/blog/how-planetscale-boost-serves-yo...
> The Boost cluster lives alongside your database’s shards and continuously processes the events relayed by the VStream. The result of processing these events is a partially materialized view that can be accessed by the database’s edge tier. This view contains some, but not all, of the rows that could be queried.
This is so freaking neat. Caching is one of the harder things to get consistently right and even if this was a tool that had TTLs+API to invalidate it would be cool but not even having to worry about that is even better.
PlanetScale continues to be an awesome service that lets you not worry about your DB and instead focus on your application.
My only wish for PlanetScale would be a few more (lower) tiers. Their free tier is very generous but has a few little things (like more than 1 dev/prod branch) that aren't supported and I always feel antsy about not having a prod-like DB for qa/staging. I normally use 3 branches and the free plan only supports 2, which I think changed, I thought I used more than 1 dev branch before I started paying.
I have a very burst-y application (it's for events, so it ramps up a few months before the event, then is crazy for 2-7 days during, then usage drops to pretty much 0 for the next ~9 months), I'd love to lower my costs for those 9 months (I could look into downgrading to the free plan but I'd rather pay just a little less and have my quotas drop accordingly). In the end PlanetScale is still worth it for me at $360/yr so I'm not complaining too much. For smaller projects I just worry about using the PS free tier since if I go over those limits the jump is steep ($0->$30/mo), that said I might be overthinking it.
[1] https://www.microsoft.com/en-us/research/wp-content/uploads/...
There's also the exotic https://dynimize.com/ (unsure of their current state).
My initial thoughts after reading the blog post, just to poke holes in their new product:
1. Costs. This can save time on read, but it is also introducing additional writes to the database, that can be pretty expensive. PlanetScale can scale horizontally, but have to watch out how much it is going to be paying for the extra machines. (Albeit- machines are usually always cheaper than developers)
2. Consistency. It was not clear if it is going to make committing transactions slower to keep all the views up to date, or if the materialized view is running slightly behind real-time.
2a. And how does the materialized view handle large/slow transactions? Is there going to be any kind of serialization locks? Are the views correct inside of the transaction?
3. Predictability. Query planning is a necessary hell, and different queries might have different patterns that might introduce slightly different materialized views, that could have been maybe served under the same view. Increasing the cost.
3a. SQL Server took a slightly different route lately for performance, in which queries will have different plans depended on the table statistics. I wonder how such a feature would play with Boost, and if slightly different query plans might generate different materialized views.
> There is a small delay between when these changes are committed to the database and when the cache has been updated. This delay is typically measured in hundreds of milliseconds. Those of you familiar with MySQL replication can think of it as reading from a replica. Typically we've found that most use cases work perfectly fine, even when returning results that may be slightly out-of-date.
As for predictability, we’re working on some interesting optimizations that allow similar queries to reuse the internal state of each other, so the system becomes more efficient the more queries it’s caching. Stay tuned!
To me, it looks like supabase is designed to take full advantage of postgres features. plpgsql triggers + RLS + clientside auth + streaming changes to subscribers (including via web hooks) are my favorite features. (They also have js edge functions, but I use lambda instead b/c I prefer python)
Supabase feels like the scrappy company with amazing focus, akin to an early MailChimp (circa 2007). PlanetBase feels more like early Snowflake - massive scale, focus on performance, can match anything feature-by-feature. One is a master of their craft, the other is a gorilla at scale.
Curious what others think. I haven't used PlanetBase extensively so don't have much to go on except their marketing.
Planet Base feels like Snowflake, or some aspects of fly.io, or timescale's managed cloud offering; their focus is on the core database tech and delivering that in a scalable manner.
I have a few extra cloud invites: greg@readyset.io
What are your core value prop differences between your service and sb? Just curious how I should think about your offering compared to what I'm familiar with.
I’ll keep you in mind for anything that does require performance! Currently I’m doing about 5 requests per day to the db layer, all from my dogfooding. With a very simple data model.
I've yet to use it on anything large-scale, though, so I can't speak to performance when you're really pushing it.
Noria: Dynamic, partially-stateful data-flow for high-perf web applications - https://news.ycombinator.com/item?id=29615085 - Dec 2021 (10 comments)
Noria: dynamic, partially-stateful data-flow for high-performance web apps - https://news.ycombinator.com/item?id=18330477 - Oct 2018 (1 comment)
Noria: dynamic, partially-stateful data-flow for high-performance web apps - https://news.ycombinator.com/item?id=18176135 - Oct 2018 (1 comment)
> When a query is deemed too complex to determine what specific cached data may have become invalidated, a fallback to a simple but effective table level invalidation occurs.
The PolyScale approach does not maintain / require a separate data representation and so saves space, but on the other hand, precisely identifying the relationship between reads and writes is not possible and so the PolyScale approach must sometimes over-invalidate in the interest of accuracy.
There are scenarios in which show-me-the-data (Noria) beats show-me-the-math (PolyScale), for example, running complex queries against a relatively simple schema. There are also scenarios in which the statistical (PolyScale) approach wins, for example if the queries are relatively simple or if not all writes to the underlying data are visible.
There are additional unique features of PolyScale that set it apart. Full disclosure, I work at PolyScale.
Here is some proper SQL query:
SELECT DISTINCT
r.id,
r.owner_id,
r.name,
COUNT(r.id) OVER (PARTITION BY r.id) AS COUNT
FROM repository r
JOIN star s ON s.repository_id = r.id
ORDER BY 4 DESC;You are counting all stars of all repos, they are counting stars of one (parameterized) repo id.
Where r.id = :repo
and you will have the same thing.
This caching does look cool, perhaps I'll revisit PlanetScale later on my own time.
For a sense of scale, we have ~150gb of data running around 5 trillion row reads + 500 million row writes per month
Just wonder: How are the DB queries from your php implementation to the Planetscale DBs affected by network latency (hops and length between servers) as well as bandwidth (query results returned by PlanetScale DBs)?
Thanks! :-)
My usage is way under some of my sibling comments but it's a been a joy to use and $360/yr to not have to worry about scaling my DB, backups, schema migrations, and now caching is a steal for me. Could I run my DB on a $5/mo DO box (or similar)? Probably, though I'd probably want at least the $10/$15 size box for when my software gets a little more load. Even if I knew for sure I could run on the $5 box I'd still rather pay $30/mo to never worry about my DB and the schema migration tool is awesome.
In short, it can be compared in consistency to an up-to-date read replica; PlanetScale Boost uses Vitess' VStream to process events as they happen and keep itself up to date. The blog has much more information if you're curious.
> Noria is a new streaming data-flow system designed to act as a fast storage backend for read-heavy web applications based on Jon Gjengset's Phd Thesis, as well as this paper from OSDI'18. It acts like a database, but precomputes and caches relational query results so that reads are blazingly fast. Noria automatically keeps cached results up-to-date as the underlying data, stored in persistent base tables, change. Noria uses partially-stateful data-flow to reduce memory overhead, and supports dynamic, runtime data-flow and query change.
Acceptable for some, maybe not others
> Powered by open source tech - Built at Google to scale YouTube.com to billions of users
Is this a Google project/business owned by Alphabet? The text seems to indicate so, but I find no information about it when doing some quick searching or browsing through the website.
See more: https://planetscale.com/vitess
So I'm guessing PlanetScale now helps maintain Vitess and PlanetScale is somewhat of a hosted Vitess for people who don't want to self-host?
And it does have great guides for use with React and Next.js
My first startup job was a skunks work project and we had around 128 noun-adjective pairs we wanted to find a .com domain for. All of them were taken.
We had to settle on a .io domain, and this was 7 years ago.
2 year in we came up with a better name and managed to get a .com... with a dash in the URL.
The cross-shop is PlanetScale vs Amazon RDS, Amazon Aurora, Google Cloud SQL, Firebase, Supabase, self-hosting Vitess or MySQL, etc.