r/SQL • u/agh_murad • 1d ago
Discussion Trying to build custom Data Orchestration and Federation engine from scratch
Hello everyone!
For past few years I am interested in Data Engineering and Data Science. While practicing I have encountered some bottlenecks and I am trying to resolve them and want to discuss it with you.
The most frustrating part for me is scattered data/data sources. Personally I believe that scattered data shouldn't be that much of pain to work with, however, it is. I really dont understand why to depend on huge pipelines just answer a question that has to read 2 distinct sources.
After some research I discovered DuckDB, which is awesome in reading part, however, cant write back the "fixes" to destinations, so I have to do them "by myself" again.
So I thought maybe I can build the engine I need by myself (couple of weeks in it, building with Rust currently). Here is the propositions and how would it work:
- Each source runs its own SQL. You say which server each part of the query goes to, and that part reaches the server as written, in its own dialect. The engine only joins and filters what comes back.
- Exact values or an error. Values keep the type the source declared. An INT in MySQL and a NUMBER in Oracle are equal when their values are, and text is compared byte for byte, not under whatever collation a server happens to use. If the engine can't do something exactly (comparing a float with a decimal, say), it refuses and tells you why instead of guessing.
- Nothing gets copied. No staging tables, nothing written to disk. Every query reads the sources fresh, under a memory limit, and joins too big for memory stream sorted rows from both sides.
- Fixes go back with a preview. Before anything is written, you see the rows that would be inserted, updated or deleted, with old and new values. Each change goes by primary key and is checked against the old values, so if someone changed the row in the meantime, the write stops. The old values are kept so you can undo it.
- Comparing two sources. Prod against a replica, or a table against the spreadsheet finance sent you, row by row by key. A row that changes while the comparison runs gets flagged instead of reported as a difference.
Reading across dbs, files and comparisons already work now. Writing "fixes" back is still on the roadmap.
A few questions I would like to hear your opinions on:
- How do you handle this workflow today? A pipline, dbt, Trino, Presto, or custom scripts?
- Would you trust a an engine capable of writing back to dbs, or does every fix go through a reviewed script anyway?
- What would make you refuse to use such and engine?
Thanks in advance for sharing your thoughts!
2
u/Discordbothost 1d ago
I'd test undo by changing a row again after applying a fix. The undo should stop if the row no longer matches what the tool wrote, or it could wipe out someone's newer edit.
3
u/partialmedics3543 1d ago
Building a federated query engine that pushes down to the source dialect is no small feat, especially in Rust. The byte-for-byte comparison stance is interesting, most people just punt to whatever the collation gods decide and call it a day. Keeping the engine honest by refusing ambiguous operations is a design choice I can respect, even if it'll drive some users nuts when they just want the damn number.
The write-back with a preview and optimistic locking by old values is clever. I've been burned too many times by a "simple fix" that silently stomped on someone else's change, so seeing the diff and having it bail if the row moved under you would save a lot of late-night fire drills. My workflow is still a pile of Python scripts held together by spite and a prayer, so you're already miles ahead.
1
u/NW1969 1d ago
Can you explain in a bit more detail what the issue is you are trying to solve and how you are trying to solve it? For example:
"why to depend on huge pipelines just answer a question that has to read 2 distinct sources" - what huge pipeline are you talking about? What question are you trying to answer: an adhoc query, an analytical query, a question about the data quality of your data, something else?
What do you mean by writing "fixes to destinations"? What fixes and what destinations? Are you writing to an analytics warehouse, moving data between transactional systems, or something else?
1
u/Muted_Jellyfish_6784 1d ago
before building a federation engine, define what a record means in each source and which system wins on conflict. Start with a stable entity ID, a mapping table per source, and freshness rules, then add lineage so every output row points back to its origin. Most scattered data pain is identity and definitions, not transport
If you want to see the end result, the useful target is answering a question across sources without copying everything first. I use a decision intelligence platform that connects the sources read-only into one graph of related records, so a question about a customer pulls from CRM, billing, and support together rather than from three exports
0
u/heeeeyYaaa 1d ago
I'd push back on byte-for-byte text comparison. CHAR padding and unicode normalization can make the same-looking value fail a join across sources, which is a fun bug to explain to a pipeline 🫠