title: Write-through cache Redis
body: <p>I have been poundering on how to reliably implement a write-through caching mechanism to store realtime data.  </p>
  
  <p>Basically what we need is this:  </p>
  
  <pre><code>Save data to Redis -&gt; Save to database (underlying)  
  Read data from Redis &lt;- Read from database in case unavailable in cache  
  </code></pre>
  
  <p>The resources online to help in the implementation of this caching strategy seem scarce.  </p>
  
  <p>The problem is:  </p>
  
  <p>1) No built-in transaction possibility between Redis and the database (Mongo in my case).<br>
  2) No transactions mean that writes to the underlying database are unreliable.  </p>
  
  <p>The most straightforward way I see how this can be implemented is by using a broker like Kafka and putting messages on a persistent queue to be processed later.<br>
  Therefore Kafka would be the responsible entity for reliable processing.  </p>
  
  <p>Another way would be by having a custom implementation in a scheduler that checks the Redis database for dirty records. On first thought there seem to be some tradeoffs to this approach and I would like not having to go this road if possible.  </p>
  
  <p>I am looking on some options on how this can be implemented otherwise.<br>
  Or whether this is in fact the most viable approach.  </p>