I don’t want to give other teams direct access to a DB and have them Not only take a dependency on the schema, but have the ability to run arbitrary queries that may exhaust resources in ways that impact normal operations. If I expose an API, I control the access patterns and can evolve the schema separately to suit the workload.
If other teams need a replica to perform their arbitrary queries, I’d much rather have them using a richer data model that they can normalize into whatever form suits their needs than have to conflate that into a source of truth data store.
If you have a single business unit and can get away with commingling concerns within a small team, great, throw it all in a single DB. If it makes sense to split, however, do it quick and early to avoid a decoupling hell that is more expensive then having split in the first place.
And then they will depend on your API data schema...
Yes, schema evolution is hard, but databases have many tools to help here that you will either have to recreate on your APIs or live without and have a harder time. Either way, all the trouble comes from data evolution, and any schema-only change is trivial to deal with.
Data distribution is something that varies from one DB to another, they usually have very good performance that is hard to replicate on your application layer, but are very hard to setup and keep running. But the point about control of resource usage is a good one.
+100 to this
The DB can do everything can’t seem to understand this, for some reason.
Of course, merging different backends can not be done on the backend. Either you add a layer or you do it on the client.
That depends on the DB's foreign table support, or equivalent, if it has it. It's certainly not categorically impossible with a DB.
Which we have methods of evolving. I can put my API in gRPC and know exactly which changes will or won't break compatibility. Try doing that with a database.
You don't have to. Package up necessary queries into views and/or stored procedures and grant permissions only on those. Views can also shield from schema changes.
What i find funny is that most dbs translate sql into an internal representation that is remarkably similar to a proper relational algebra and optimise on that. I'd really just prefer the alebraic language as described in the original ages old paper.
There were also a few dbs trying to push sql-but-better languages... haven't heard about them for a while.
Each query script would act on a few objects in global scope: `db` (handle to database), `start`, and `end` (time range of grafana dashboard that query was for).
I found being able to write imperative (rather than declarative) code to build a query to be extremely powerful, especially for storing variables and looping over things.
e.g. query script - just to get a feel for it:
let dalmp = db.ts("pjm-da-lmp/western-hub") // ie retrieve the timeseries named 'pjm..'
.with_time_range(start, end);
let rtlmp = db.ts("pjm-5min-lmp-rt-lmp/western-hub")
.with_time_range(start, end)
.resample("1h", "mean");
let da_err = rtlmp.diff(dalmp);
#{
dalmp: dalmp,
rtlmp: rtlmp,
da_err: da_err,
}
A query script would be expected to return a dictionary-like object. the keys would be used as labels and the values would each be a time series object.This is not the perfect solution for every problem but though it might be interesting to see an example of a very different approach to querying compared to sql.
One big thing is that NULL should never "mean" anything in a business sense. It is the absence of a value, hence it cannot mean anything.
By the same token you need to understand how your database handles concurrency. Different databases do it differently.
I always had a problem with that notion. I mean, it has a memory representation, it has a set of operators you can apply to it, defined behavior in UNIQUE and FOREIGN KEY constraints etc. All this is well documented (though can behave slightly differently between databases, as you mentioned).
So, it has a set of valid values (just one: NULL) and a set of valid operations, so it's a type!
And now you have a type that looks somewhat similar to a null in "normal" programing languages, and SQL generally lacks the mechanisms for inventing your own types, so why wouldn't you use it in your business logic where it makes sense?
The design of NULL seems like a historical accident anyway. The best I can discern, there was a need for something to behave as "excluded" in the context of FOREIGN KEYs and outer joins, and so that semantic was just passed along to other areas where it made less sense.
I think a better type system and a better separation between comparison logic and the core type would have obviated most of the NULL's weirdness and made it far less foot-gunny in the process...
Unfortunately the problem is made worse by the proliferation of languages making the equally heinous mistake of treating null as "false-y". Bad form, Peter, bad form!
But! As somebody with a relatively good understanding of a history of sql, relational dbs and related concepts I have to add: SQL is often to blame.
All the the amazing engineering that goes into database engines, clean and coherent ideas of relational algebra, optimisability of a declarative approach to computaion - all of that gets bad rep because of the nightmare of sql-the-language.
The standard, the syntax, every little bit that could go wrong is just wrong from the point of view of a language designer. Composability, modularity, predictability, even core null-related defaults.
But it's everywhere. We just have to accept it.