How to persist data into a table using only WSS ? #47841
Replies: 4 comments 6 replies
-
|
Supabase Realtime is not the write path I would use for this. Treat the WebSocket as your app transport to trusted server code, then write to Postgres from there: client -> WSS Edge Function/custom server -> authenticate + validate payload -> insert/RPC -> socket.send({ ok, id or error }). Keep the service-role key only in that server code. If clients are allowed to write directly, the normal Supabase path is PostgREST/RPC with RLS; Realtime is better used after the insert for fan-out/subscriptions, not as the mechanism that inserts rows into your table. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @yakubka, Now that I've almost finished everything and it's working, i discovered that Edge Functions don't keep WebSocket connections open for more than 150 seconds on the free plan and 400 seconds on the paid plan. Does an HTTPS POST request with the |
Beta Was this translation helpful? Give feedback.
-
|
That’s very strange, because Supabase Realtime is supposed to allow persistent connections, and the server processing for this, is supposed to be the same. Furthermore, if the connection drops, I will reconnect immediately afterward, which will consume more server resources than simply keeping the connection open. |
Beta Was this translation helpful? Give feedback.
-
|
The hosted Edge Function limits do apply to a WebSocket handled by that function. Supabase Realtime and Edge Functions are separate runtimes: Realtime is a persistent Elixir/Phoenix WebSocket cluster, while an Edge Function worker has a maximum wall-clock lifetime of 150 seconds on Free and 400 seconds on paid plans.
For ESP32 telemetry on hosted Supabase, I would use:
Realtime Broadcast can carry client messages over a persistent WebSocket, but it is a messaging service and does not turn arbitrary client messages into durable rows in your application table. Its persistent connections also do not run inside your Edge Function. If a permanently connected custom WSS ingestion protocol is a hard requirement, the WebSocket server needs to run outside hosted Edge Functions and write to Supabase from trusted server-side code. References: Edge Function limits, Realtime architecture, and Storage resumable uploads. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I am building an application where I want to handle data persistence exclusively through Secure WebSockets (WSS).Instead of using traditional HTTP REST endpoints (like POST or PUT) to save data, the client will send a JSON payload or bin payload over an established WSS connection, and the backend should insert this data directly into a database table.
My questions are:
What is the best architecture or pattern to handle database writing operations through a continuous WSS message stream ?
I just need a response from the server:
either "inserted in the table OK" or "not inserted" with the error reason.
Thank's
Beta Was this translation helpful? Give feedback.
All reactions