This repository has been archived by the owner on Oct 21, 2020. It is now read-only.
Why Prisma should avoid polyfilling (for now) #330
Labels
area/missing
keep
kind/discussion
Discussion about if and how something should be written down in a spec
I want to share my thoughts on why starting with database-level features first is important for us from a product and strategic perspective.
Where we are today
The diagram below shows the life a query in both Photon and Lift. I've oversimplified the Datasource server into Handler and Storage.
You can apply this simplification to Postgres, MySQL, SQLite, Mongo, Redis and HTTP APIs.
To be a viable query builder and migration tool, there are certain features that we just need to have. Some of these features include:
now()
,generate_uuid()
, etc.The datasource's Handler offers these features on top of pure Storage.
Databases like Postgres, MySQL & Mongo support many of these features natively, while databases like SQLite and Redis support some of these features. APIs like Stripe support very few of these features.
With Prisma's architecture, we have the opportunity to "polyfill" data sources with additional features they don't support natively. We can polyfill in the Query Engine and in the Migration Engine.
This opportunity presents a question: when should we polyfill?
In the past, Prisma polyfilled many parts of the database. This made sense at the time when Prisma managed the database. Introspection changes the game. We now have to deal with an existing database's warts and all. This has led us to re-evaluate polyfilling for features like native scalar lists and cascading deletes.
Our current decision-making is feature-based, but I think we need to think higher-level. We need to develop a default position, where we prefer one decision over the other until the tradeoffs are too great. It's our own version of "innocent until proven guilty."
I believe that our default position should be: "database native until proven otherwise".
Why should we adopt "database native until proven otherwise"?
From a product perspective, we should be database native for the following reasons. Native allows:
From a strategic perspective, we should be database native for the following reasons:
What does this change mean for us?
Database-first requires a change in mindset:
This mindset is similar to going serverless, where you innovate within the constraints of AWS. We'll innovate within the limits of our target datasources.
This also means we'll need to finalize parts of our Schema like custom types which are essential for being database native.
Tradeoffs
I've made quite a few tradeoffs in this proposal:
String[]
are not possible everywhere.cuid()
would be out of scope and not universally available.plpgsql
function to provide this.Again, I lean on the comfort that we can come back to Prisma-level features when companies with big pockets come knocking. Companies like Facebook and Github do not use foreign keys because they're too slow. I'd love to solve their problem at the Prisma-level when the time comes.
Footnotes
[1]: I encourage you to watch this video on SQLite to get a better sense of just how
battle-tested databases like SQLite are.
The text was updated successfully, but these errors were encountered: