Path forward for Web -> Flutter -> Couchbase?

Hello all!

My team is working on a project that will allow the use of Flutter via a browser AND for mobile apps that uses Couchbase on the backend. While I’ve seen a number of libraries for mobile apps that use couchbase, I’m not seeing anybody doing similar things for a browser-based scenario. I’m honestly not even sure what the solution looks like - and, in a perfect world, I do not want to reinvent the wheel. Perhaps someone could point me in the right direction? I imagine that there are numerous browser-based solutions to using Couchbase?

The two possible paths I’ve seen are as follows:

  1. A flutter/dart library that, when run in a mobile app uses something like Fluttercouch to interact with Couchbase BUT when run in a BROWSER instead makes synchronous REST calls to sync gateway.

  2. A flutter/dart library that is similar to the above but, when run in a BROWSER, opens a websocket to sync gateway.

I’ve got a team working on option #1 - but am very concerned about the performance of that solution. I’m (possibly) forming a second team to work on option #2 - but I really don’t know how that would work. While it should be easy enough to open a web-socket in a browser with a flutter library, I’m not sure what is really supported by Couchbase and Sync Gateway in this scenario. Would love to hear people’s thought and/or talk to someone who knows more about this than I.

Thanks - and let me know if you have any questions.

Hello, the best way to do this while maintaining a consistent experience everywhere would be to compile Couchbase Lite to webassembly. I believe @gabriel started doing this a while ago but not sure where that went. And as our main Flutter champion and Couchbase ambassador, he will probably have a much more precise opinion than mine on the matter.

I had use PouchDB years ago and it worked fairly well. So 1, although not ideal, was doable. I guess it depends on the kind of realtime feel you want for your application.

Hey @kingDaddy, I’m the author of CBL Dart, which you might have come across already.

As @ldoguin mentioned, I have experimented with compiling Couchbase Lite to WebAssembly. Getting Couchbase Lite to compile to WebAssembly is relatively easy. The issue that is blocking this from becoming a real option in the short term is that some browser APIs (e.g. efficient access to a File System) that would be required for a complete and performant implementation are only just in the process of being specified. Another potential problem is that the subset of browsers that currently support all the required WebAssembly features might not be sufficient, depending on the project.

I think option 1 could be viable, depending on the use case. What would be the access patterns of the Sync Gateway? If you had to poll the Sync Gateway for real-time updates, that could make scaling this solution hard.

Option 2 would certainly be something very interesting to have in general for the Dart/Flutter platform. I could imagine an API that does not support any persistence, only connecting to a Sync Gateway. There have already been some requests for Couchbase Lite support for the Web, but this might be what is more needed than a full Couchbase Lite Web implementation. This could be implemented fully in Dart, not requiring any support for WebAssembly or early-stage web APIs. The first step would be to implement the BLIP protocol in Dart. This is the protocol through which messages are exchanged between Couchbase Lite and Sync Gateway, and works on top of WebSocket. If you have that, you can implement the Connected Client protocol.

1 Like

Hello Gabriel! Thanks for the above response. Yes, I’m a big enthusiast of Couchbase Lite for Dart - been using it for about a month. It’s very impressive. I’m unable to determine which version of Couchbase Lite (the couchbase product) it is actually using… More importantly, do you have any thoughts on when YOUR Couchbase Lite for Dart will support named collections and scopes?