What is my best approach for sharing an sqlite database stored on an attached volume?

I have an already production instance with an attached volume storing an sqlite db.
We have another service, written in a different language that’s separate but was written expecting a similar db on disk.

Fly doesn’t let you multi attach a volume (AFAIK). Using an external service means changing both our codebases and change libraries.

I can send the file to a remote storage and this way sync it with the other service but that’s not ideal in terms of data consistency.

I also don’t want to pack both applications in the same container, feels like running both a compiled go backend and another typescript based service in the same container is a bad antipattern.

Any ideas I’m not aware of?
Will LiteFS help with this somehow?

Hi… LiteFS would definitely help if one of the two services was read-only.

Otherwise, LiteFS is typically not well suited… It can apparently handle occasional writes with litefs run, but that would require the kinds of modifications you’re trying to avoid.

(It looks like that might also be painful with Javascript, due to the need to launch an entire temporary Linux process just to perform a single write, etc.)

Added litefs, sqlite

Actually the js is only a statistics service reading data, no writes!
In this case I’ll take a look at litefs

1 Like

@benbjohnson, is it possible to have multiple services using the same databases using LiteFS?

I don’t know if this is possible, but using the same consul configuration in the “litefs.yml” file of the different services could be a way to share the databases between multiple services.

consul:
  # The URL of the Consul cluster.
  url: "__SAME_FLY_CONSUL_URL__"

  # A unique key shared by all nodes in the LiteFS cluster.
  key: "__A_SHARED_KEY__"

And, in your only write App, set the candidate as false:

# Specifies if this node can become primary. The expression below evaluates
# to true on nodes that are run in the primary region. Nodes in other regions
# act as non-candidate, read-only replicas.
candidate: false

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.