I propose that you get familiar with Yjs’ Update API. You simply need to ensure that all updates are propagated to all users and also stored in a database (the order in which they are delivered/stored doesn’t matter).
However, I found it difficult to understand whether we can also set up some “track changes” and also restore a previous version like in Google Docs. Can you help me here?