Search code examples
javastream

Fetching Data from DB using streams


Recently, I was asked how to retrieve data from a database without using SQL queries. They suggested using streams to accomplish this, and I'd like someone to explain how this can be done.

I initially mentioned ORM frameworks, but the interviewer said that wasn't the right answer as the frameworks use sql queries against the database to retrieve data.


Solution

  • It's possible that the answer they were looking for is log-based Change Data Capture (CDC), either via established tools like Debezium or custom-built CDC connectors. The gist of this approach is to read directly from the write-ahead log as CRUD operations happen in the database, rather than poll the database on some cadence using SQL (aka query-based CDC).