Writing Client Changes
Your app backend needs to expose an API endpoint to write changes to your backend database that are received from the PowerSync client.
This could be:
- A single endpoint accepting a batch of changes from the client, with minimal client-side processing.
- Separate endpoints based on the types of changes.
- A combination of the above.
For details of the client-side interface to your backend, see Integrating With Your Backend.
It’s important that your endpoint be blocking/synchronous with underlying Postgres or MongoDB writes.
In other words, don’t place writes into something like a queue for processing later — process them immediately. For more details, see the explainer below.
Changes recorded on the client
The change queue on the client stores three types of operations:
PUT
/ Create new row — contains the value for each non-null column. Generated byINSERT
statements.PATCH
/ Update existing row — contains theid
, and value of each changed column. Generated byUPDATE
statements.DELETE
/ Delete existing row — contains theid
. Generated byDELETE
statements.
Recommendations
The PowerSync Client SDKs do not prescribe any specific request / response format. Custom client-side code is used to communicate with your app backend, and can use any format.
We do recommend:
- Use a batch endpoint to handle high volumes of changes.
- Use an error response (5xx) only when the changes cannot be applied due to a temporary error (e.g. database not available).
- For validation errors or write conflicts, acknowledge and discard the change. If an error is returned for this, it will block the PowerSync client’s upload queue.
To propagate validation or write error messages back to the client, use:
- A 2xx response, with details in the response.
- Write the errors back in a separate table that is synced back to the client.
For details on approaches, see:
For details on handling write conflicts, see: