title: Kafka Streams: Implement a simple KeyValueStore where I can put and get data
body: <p>I have a Kafka streams application which operates on the incoming state and need to store the state before writing to the next topic. The write should occur only after  the state is updated in local store. </p>
  
  <p>Something like this.</p>
  
  <pre><code>stream.map(this::getAndUpdateState)
            .map(this::processStateAndEvent)
            .to("topicname");
  </code></pre>
  
  <p>So that in <code>getAndUpdateState()</code> I can do like</p>
  
  <pre><code>state = store.get(key); // or new if null
  state = updateState(state, event);  // update changes to state
  store.put(key, state);  // write back the state
  return state;
  </code></pre>
  
  <p>How do I implement that simple get() and put() operation on a kafka store? I already tried using <a href="https://kafka.apache.org/10/javadoc/org/apache/kafka/streams/state/KeyValueStore.html" rel="nofollow noreferrer">KeyValueStore</a> but it had issues as I had to add it a source and sink processor and all.</p>
  
  <p>Alternatively, a way to get and put in kafka using a KTable or some other concept is also fine.  </p>