Im a newbie creating a document editor and idk how to setup an architecture to save the data

I'm using tip tap for the editor on the front end while using Postgresql with bun on the back end. I have an idea of how I could do it, but it seems not that effective, I would like your suggestions for another solution. I am thinking of saving the document content in a JSON format, as tip tap allows you, and saving it into a Postgresql row. The problem is that every time you update the document, you are sending the whole document content in a request, which would make each request to be very heavy, even if you just updated a single character. This would consume a lot of bandwidth for both the user and the server.
No description
7 Replies
Gad
Gad3mo ago
honestly, it should be fine imo unless there are embedded fonts or images, it isnt really that much data
Huilen
Huilen3mo ago
isnt it?
Max
Max3mo ago
Yeah just save it as json. if you're using prisma you can set it as a field in a table as Json. and if using prisma use a transact to make sure your delete and create prisma queries work. If it deletes and create fails it will role back and throw an error.
Mocha
Mocha3mo ago
What's your main concern here? Cost of bandwidth? Time to update? Cost of storage? * If it's the cost of bandwidth, and this is a new project, then I'd say this is premature optimization, which I get it, I'm guilty of this habit too : ) * If you're worried about the server handling too much, then you're fine. The server won't do much with it more than copying it. * Storage is cheap, so no worries, at least for now. * Time, the user doesn't need to await a result * Also, you're probably already doing this, but consider adding some sort of delay. One character maybe isn't worth sending a whole request, so you can wait till either the user types 3 chars or 3 seconds pass.
Huilen
Huilen3mo ago
thank you its ttrue maybe i can call editor.getText() and compare the strings and count the differences and i can make use of delays too I was just worried that I was going to choose this approach over the more complex one of detecting each transaction on the editor and sending it to the backend to in some way be able to manipulate the JSON but I was worried unnecessarily
Mocha
Mocha3mo ago
Yes, especially if this is a personal project, please ignore that and just try to ship something functional as soon as you can. Nothing else matters before production. You can always optimize later, when you know more about what you wanna do!
Huilen
Huilen3mo ago
right