Design pattern to sync local databases with the cloud

This is called a “distributed database”, and it is extremely hard to do well. For almost all cases you should have one database in the cloud and have all the apps use it in the normal way through an API.

If you absolutely have to support disconnected operation, you may need a distributed database. Such as if one of your clients goes off-grid for a while, needs to make changes, and then reconnect.

But then you face the central problem: what if two clients go off-grid and make different changes to the same data at the same time?

The state of the art in techniques for dealing with this is the conflict-free replicated data type.

Rolling your own technology for this will probably add a year to your project and give you at least one significant data loss incident.