Direct syncing between devices, without sync server

First, kudos: Anki has made syncing very smooth.

The syncing is done via a sync server, by default AnkiWeb, which requires only a free account, but it’s also possible to use a self-hosted sync server (djankiserv, anki-sync-server), though it’s a bit of a hassle (or, to many, infeasible).

However, I wonder how a user can sync directly between devices, conveniently, without involving the “cloud”?

Now my usage pattern is very simple. I use the computer to add cards, and do the reviews in AnkiDroid on the phone. Grateful I am for the free AnkiWeb service, still it does strike me unnecessary to rely on a server at all. Clearly, this design choice was made deliberately. And most users are well served by it, in most cases. But I’ve always made sure not to put any sensitive information into Anki, because it would be uploaded to AnkiWeb’s sync server. It would be nice, if we could sync between devices directly, even if a little less smoothly.

Obviously, we can always export & import, but that’s much too inconvenient. Directly syncing files under ~/.local/share/Anki2/<profile>/ (on the computer, Linux) and those in AnkiDroid’s data directory (on the phone) is an idea; syncing this way could conceivably be made rather easy. However, files under these two folders aren’t identical; how would one safely go about this?

Or it may be that this requires support in the software, both in Anki Desktop and the mobile clients. Maybe, say, Anki Desktop itself could be a sync server? And to sync with the phone, we would scan a QR code presented by Anki Desktop. Or, perhaps introduce a truely P2P/decentralized sync protocol? Let’s hear your ideas.

1 Like

Unfortunately, having a central sync server is not just a matter of practicality for most users (who would prefer that to P2P), it’s also necessary when you are trying to maintain synced several clients. What I mean by that is that, as with most vc software (such as git), when you have this client / server setup, you only ever need to do two-party merges (that is, merging the client’s version of your collection with the server’s version).
This seems easy enough when you only do fast-forward, that is, whenever I make changes on a client, I sync to the server and then sync to every other client so that everyone is up-to-date before making new changes. It becomes harder, much harder when each client may have some progress independently and then tries to merge. It’s so hard that sometimes Anki does not know how to solve that in a “proper” manner and just gives up, saying “which version would you like to keep, and which one to throw away”?
Even more sophisticated vc software have the same issue and, even though they let you do more fine-tuned merges when they can’t figure it on their own, it’s still a hard problem.

Now, doing this with in P2P implies achieving merges between any number of parties (because there is no central authority that is the only person each client should deal with; instead every client has to take into account all the modifications that every other client has made). This is probably way too complex for Anki (in the sense that it would require a lot of changes in the way it makes syncs), but for the user too: Anki would find itself in those situations where it can’t merge on its own, so it asks the user, and then the user would have to merge not two different versions of your collection, but an arbitrarily large amount of them.

This rules out a decentralized sync protocol, but I think you can “mimic” it by having a local sync server, that is, your sync server needs not to be in the “cloud”, you can just run it on your machine and just those on your LAN (and who have an account, which only you can create) can sync.

3 Likes

Good point. So a “truly decentralized” protocol is out. Naturally, there is an inherent conflict between mutability and decentralization. For example, BitTorrent is P2P/decentralized, but the data is immutable.

as with most vc software (such as git), when you have this client / server setup, you only ever need to do two-party merges

I like the git analogy. With git, it’s not necessarily client-server: we can merge two branches, or two local repositories (the terminology is local vs remote). With Anki, two-party merges are all we need, too. It would be nice if all Anki clients had a “sync server” (or “git”) inside, so that we could sync two devices directly (“D2D” or “C2C”). The workflow can be quite smooth, with QR code scanning, for example.

PS:

The problems with setting up a LAN sync server include: 1. It requires effort and a level of technical know-how. 2. You don’t always have access to that LAN. And if you’ve set up the sync server on your computer, you will need to change the IP address of the sync server constantly in order to sync. (Or use some domain name service, another barrier.) (Or: with modifications to the mobile clients, the sync server can be updated with a QR scan, making it more convenient, but still not quite smooth; and point 1. still stands.)

(The file-based syncing mentioned in OP, including export & import, is of course not feasible, unless you’re very careful not to “branch” (bifurcate) the data: no merging is done.)

Well, depends on your distribution. Some distributions (two, according to repology: Arch (unofficial package) and NixOS (under the name ankisyncd)) do package it, so it’s really easy to install on those.

This is most likely because your rooter uses a DHCP server to handle IPs (that is, it will deliver an IP to whoever needs one; as opposed to there is a list of statically defined machines → IP tables). However, even then it’s possible to have a bit of the two systems: most ISP’s rooters allow you to have static leases, that is, it’s possible to say: “do your usual stuff with IPs, except for my computer, which must always have this IP (and don’t use that IP for other computers)”. I don’t know how easy / hard it is to do that in general, I know that, with my ISP, it’s just a matter of a few clicks to configure that.

Note that DNS are used outside of the LAN, not inside (I mean, yes, you could run a local DNS server but that would be probably way too overkill, no matter what you are trying to achieve).

However, people have already though that this was a bit of a pain in the ass, so that’s why there is something called Multicast Domain Name Server (usually mDNS). It works by making available your computer on the LAN at the address hostname.local, where hostname is the hostname of your computer. .local is a SUDN, meaning that it was specially though as a “private” domain name. To make it work, you only need to install avahi on your computer, and then you’ll be able to use yourcomputer.local instead of its IP.

Thanks for the informative reply.

The mDNS bit is great! However, it’s not enough that the computer broadcasts its address, the client needs to understand it as well. Unfortunately, it seems Android didn’t fully support it until very recently, and only in Android 12; so users of Android 11 or older are out of luck.

The installation of the sync server plus its setup I suppose are doable, if I have to. If I could get mDNS to work with AnkiDroid (still on Android 11), it would be a viable option. (The static LAN IP option is no good, because I don’t always have control over the router.)

The ideal, to me, is still a device-to-device sync function built into the Anki clients. I guess this would be a major undertaking, but let’s discuss it anyway!

Holy shit! Did I make a discovery: Anki has a (yet experimental) builtin sync server.
BRB testing this shit :smiley:

I wonder if this can potentially be turned into a device-to-device sync feature…

Update: well, not what I hoped it would be. It’s a separate sync server (files placed in ~/.syncserver/). I was hoping it would sync directly out of the profile directories…

Update: The builtin sync server supports media syncing now:

https://docs.ankiweb.net/sync-server.html

1 Like