r/SQL • • 16m 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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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:

  1. How do you handle this workflow today? A pipline, dbt, Trino, Presto, or custom scripts?
  2. Would you trust a an engine capable of writing back to dbs, or does every fix go through a reviewed script anyway?
  3. What would make you refuse to use such and engine?

Thanks in advance for sharing your thoughts!

2 Upvotes

3 comments sorted by

2

u/partialmedics3543 9m 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/agh_murad 2m ago

Python scripts is one of my nightmares too lol! I was so tired of these issues that i decided to resolve it on my own by building a custom engine. I know it would be a very long path, however, I am really dedicated to it. Actually it is very fun project and I practice a lot while building it. Personally, I believe it would solve the issues I mentioned if done right, what do you think?