Transaction issue
hamzamajeed01
FREEOP

a year ago

Context:
We're building an application where users create a case and upload documents. Backend is hosted on Railway, frontend on Vercel, and Supabase Cloud is our DB.

Summary of Issue:
In production, we intermittently face a visibility issue where newly inserted case records are not immediately retrievable post-transaction. This happens ~1 in 5 times.

Key Observations:

  1. No Transaction Errors:
    All case creation flows complete without error. We’ve tested various isolation levels (including SERIALIZABLE) and ensured proper transaction wrapping across related inserts (e.g., case + structured analysis).

  2. Delayed Read Visibility:
    Reads immediately after the insert sometimes return no data. The same record appears on the second or third retry — indicating potential read replica lag.

  3. Local vs Production Behavior:

  • Local (Direct Connection): No lag; reads are consistent.

  • Production (Pooled Connection): Read issues appear intermittently — likely due to Supabase’s connection pooler routing reads to replicas.

  1. Structured Logging & Audit:
    Logs confirm the insert occurred, but follow-up reads failed. Even with forced retry + backoff, the issue persists.

  2. Merged Transaction Experiment:
    Merging case, structured_analysis, and steps into a single transaction avoided the error — but sometimes the inserted data itself was missing, and post-insert logs weren't generated, suggesting visibility issues post-commit.

Ask:
Do you also think that the issue is because we are using three different cloud setups a network lag ? as it happens 1 or 2 times in 5 to 10 transactions.
We suspect the read-after-write lag due to replica reads in Supabase’s pooled setup. Would appreciate any official insights, recommended config changes, or ways to ensure read-after-write consistency in this environment.

Solved

6 Replies

hamzamajeed01
FREEOP

a year ago

5ea4816f-a852-4d80-bfc8-f6cfb339f22d


a year ago

That doesn't seem related to Railway… I think that your stack being on three different networks will definitely cause some latency issues, are they all on the same region?


hamzamajeed01
FREEOP

a year ago

Railway Region: US West (Oregon,USA)(2 instances)
Vercel :Washington DC (USA East)
supabase is on US west

We also think that it is a network latency issue. That said, I want to know whether we have a way to monitor railway logs to confirm that this is a latency issue(we already have logs for our application but is there any way to get more transparency or any suggestion). My second question is whether, we can move our supabase db and host it on railway as well to quash the latency possibility?


hamzamajeed01
FREEOP

a year ago

Vercel :Washington DC (USA East)


a year ago

There is a supabase template you can try out. Take a look

https://railway.com/template/supabase


a year ago

!s


Status changed to Solved adam 11 months ago


Loading...