We’re currently designing an offline-first app but are a bit unsure how to best leverage the great sync features of CBL while not violating the service-oriented principles.
To be more specific, we’re concerned that having the app write directly into the synced DB would bypass any validation / logic implemented in the services managing these entities, unless we duplicate this service logic on the client.
We have been considering 2 options:
1: We could implement a shared service layer, deployed in both client and server. The mobile client would just call this locally as a direct library call, while other consumers that don’t have offline sync would just call the web service - this is doable as client and server are developed in the same language, but still seems like duplicating things - and there’s always a risk of the client and server logics to be on different versions of the service code.
2: Alternatively, we are considering taking the approach of:
- Letting read flows access the local mobile db directly however it needs - basically considering that for read flows, the db schema is a committed contract and the read logic is basic enough to be duplicated on client and servers
- For write flows, essentially ban direct local writes. All writes go through the server, and we’ll wait for them to be synced back to the device for reading. And to support an offline mode, we’d persist the service call requests locally into a distinct db (not synced, or synced just for backup purposes, but not actually doing any functional transactions into our main entities).
Of course that’s not really a Couchbase question, I’m just wondering if anyone has thoughts based on experience, or best practices to share…