How do you ensure consistent client reads in an eventual consistent system?

前端 未结 3 1489
自闭症患者
自闭症患者 2021-02-04 21:16

I\'m digging into CQRS and I am looking for articles on how to solve client reads in an eventual consistent system. Consider for example a web shop where users can add items to

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 22:03

    There are a few different ways of doing it;

    Wait at user till consistent

    Just poll the server until you get the read model updated. This is similar to what Ben showed.

    Ensure consistency through 2PC

    You have a queue that supports DTC; and your commands are put there first. They are then; executed, events sent, read model updated; all inside a single transaction. You have not actually gained anything with this method though, so don't do it this way.

    Fool the client

    Place the read models in local storage at the client and update them when the corresponding event is sent -- but you were expecting this event anyway, so you had already updated the javascript view of the shopping cart.

提交回复
热议问题