Search code examples
apache-kafkaapache-kafka-streams

How KeyValueStore allows write operations (Kafka Streams)


I am trying to understand kafka stream's Statestore. I understood some basics of it. I looked into the code.

Here is the declaration of StateStore:

public interface StateStore { }

One of the interfaces which extends StateStore is KeyValueStore.

Here is the declaration of KeyValueStore:

public interface KeyValueStore<K, V> extends StateStore, ReadOnlyKeyValueStore<K, V> { }

Here is the declaration of ReadOnlyKeyValueStore:

public interface ReadOnlyKeyValueStore<K, V> { }

My doubt is this:

public interface KeyValueStore<K, V> extends StateStore, ReadOnlyKeyValueStore<K, V> { }

How KeyValueStore is allowing the following operations (taken from its java-doc_):

/**

  • A key-value store that supports put/get/delete and range queries.
  • @param The key type
  • @param The value type */

KeyValueStore is extending ReadOnlyKeyValueStore. So how is it possible?


Solution

  • It's just an interface, there's no logic that explicitly limits the ability to write.

    The only difference is the addition of the put and delete method(s). The get method is obtained through inheritance of the read-only store interface

    https://github.com/apache/kafka/blob/trunk/streams/src/main/java/org/apache/kafka/streams/state/KeyValueStore.java#L40