Search code examples
javaapache-kafkaapache-kafka-streams

Can I write to a KTable in a similar way as to normal databases?


When using Kafka Streams, I know it's possible to create KTables by operating on a stream and somehow transforming/aggregating the data in it. But I was wondering if it's possible to use it in a more traditional way, like for example in relational databases.

In a relational database you can have a repository that allows saving to the table:

class MyRepository {
  private final JdbcTemplate jdbcTemplate;

  void save(int number) {
    jdbcTemplate.update("insert into my_table(number) values(?)", number);
  }
}

And then you can call this method anywhere in the code and the row will be saved in the database. Is it possible to do something like this with a KTable, or is transforming streams the only way to put the data into KTable?


Solution

  • No. KTables aren't exposed via TCP protocols such as JDBC.

    KTables are KV stores, not relational. They support range queries or key lookups, only. And you put data into a StateStore from the Processor API.