Skip to content
Sign upLog in
← Back to Community

Replit Database Updating

Profile icon
Smart0ne

So I had this idea to use the replit database as a server. I'm wondering how often does the replit database update. For example, if I have two clients and one of the sets "server" to "hi" by

db["server"] = "hi"

and the other client has

if db["server"] == "hi": print("THEY SAID HI")

will it print "THEY SAID HI" if we run those two programs at pretty much the same time (well, the database "server" is updated to "hi" first)?

Voters
Profile icon
abdussalim
Profile icon
Smart0ne
Comments
hotnewtop
Profile icon
RalfPi

Have you managed to use the Replit database as a server? The following link https://docs.replit.com/hosting/deploying-http-servers describes how to make Replit host your database. There are many complaints about Replit as a host, but since I started using it, no problems have appeared.
The most vivid example is the database I bought from https://www.globaldatabase.com/data-enrichment, hosted by Replit for a year now.

Profile icon
Coder100

The best way to guarantee this is working is to do something like this:

db["server"] = "hi" while not db["server"]: pass # ... still loading print(db["server"])
Profile icon
CodeLongAndPros

@Coder100
Wait would it not be better to time.sleep(0.5) to avoid a DoS?

Profile icon
Coder100

@CodeLongAndPros
ah yes, forgot about the fact the requests will be quite continous
but then, that could affect performance

Profile icon
Coder100

@CodeLongAndPros
ideally what happens is that the requests go one after another, assuming they block the thread (which I think they do)

Profile icon
CodeLongAndPros

@Coder100
Or even just 100ms

Profile icon
CodeLongAndPros

@Coder100
Or even just 100ms

Profile icon
Coder100

That's subjective to server speed.

Profile icon
ReferenceError

Using a database as a realtime server is probably the worst idea i've heard in a long time. Python captures the current instance of the database client side when you run the program, there is no connection to the server when running. Like for example, you can't edit your code when you're running, it's not gonna update during runtime.

Edit: To clarify, clients can edit the database but will have to run the program again before they see changes in the database.

Edit: I was proved wrong, see above comment.

Profile icon
Smart0ne

@ReferenceError
Oh :( Sad.

Profile icon
ReferenceError

@Smart0ne
What you're looking for is tcp sockets.

Profile icon
CodeLongAndPros

@ReferenceError
Uhh no that's not true...
I can (using cURL) change a key and see a value right after.

Profile icon
ReferenceError

@CodeLongAndPros
Ah, that's my bad then. I thought of the client to not have a connection to the server during the runtime and transfer the updated data after the program has been stopped.

Profile icon
Smart0ne

@ReferenceError
@CodeLongAndPros
So will it update on the second client ? (im beginner at server, sockets, etc)

Profile icon
ReferenceError

@Smart0ne
That's what I want to know as well - I thought that you couldn't have databases that updated live during runtime on both clients - It is true you can edit the database and see changes clientside, on the client that updated or made the key, but yeah will the second client see the changes live during runtime?