title: Consistency of shared, distributed cache
body: <p><a href="https://i.stack.imgur.com/83HCC.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/83HCC.gif" alt="enter image description here" /></a></p>
  <p>Let's look at the simple schema of my system. Basically, there are two (or more) services that make simple operations on the SQL database: READ, UPDATE, WRITE. After writing (reading) an entry <code>E</code> to (from) database it is written to a distributed cache (Redis). The following reads of <code>E</code> will be read <code>E</code> from Redis cache to achieve higher throughput. Basically, it works correctly.</p>
  <p>However, I consider the following situation:</p>
  <p>Cache is empty.</p>
  <pre><code>Process A (reads the entry `E`)     Process B (updates the entry `E`)           
     
  READ(E, cache) = EMPTY     
  READ(E, db) = E1
                                            WRITE(E2, db) 
                                            WRITE(E2, cache)
  WRITE(E1, cache)                          
       
  </code></pre>
  <p>So, finally, there is outdated <code>E1</code> saved to cache.</p>
  <ol>
  <li>Is it eventual consistency?</li>
  <li>How to resolve my problem?</li>
  <li>Could you recommend me something to read about such problems and methods to resolve them?
  I know something about distributed systems (like CAP theorem and so on)</li>
  </ol>
  <p>Thanks in advance.</p>