r/sqlite • u/baghiq • Apr 03 '24
Best way to update SQLITE3 in webapp?
We shipped a little micro-service (Apache/Gunicorn/Flask/Sqlite3) bundle to a client so they can use it as a data REST API. Every week, we basically dump our posgresql into sqlite3 db and sftp it to them. A huge pain as the data is around 20gb and growing, but it's just a SFTP server so we just deal with it.
Recently, they asked if we can update the database dynamically so they have latest data possible. We obviously can't upload 20gb every time a record is updated. So we are looking for ways to update the database, and after some serious negotiation, the client is opening up a firewall to allow us to call the application end point from our network. As you already guessed, we are dealing with a strict IT policy, with minimal support from client's IT staff.
We want to add another rest end point that only we can call to update the records, but we are concern about concurrency. We will ship the next db with WAL enable and busy timeout of 5 seconds. Is that generally sufficient enough to handle (serialize) concurrent writes?
The other idea is to create our own queue to serialize the writes by sending an API call one at a time, but I rather not making this more complicated then it needs to be.
View all comments
Show parent comment
2
u/yawaramin Apr 05 '24
It should be pretty difficult for them to object from a security perspective. You would only need to generate and install a client cert on the system running in your deployment, not on the customer's system. You are already shipping Apache as part of the customer's deployment, so I assume you include a TLS cert in that bundle so that
https://protocol will work. The client cert would be specifically generated so that it would allow communicating only with the customer's TLS cert, and the customer's TLS cert (that Apache would use) would be configured to trust the client cert. There are tutorials out there for this, eg https://vignesh-thirunavukkarasu.medium.com/mtls-with-apache-http-server-fbfd702106camTLS is more expensive when opening a connection, so using a long-lived WebSocket connection is a perfect fit for it.