Skip to content

feat: Initial PoC#1

Draft
Chriztiaan wants to merge 3 commits into
mainfrom
feat/init
Draft

feat: Initial PoC#1
Chriztiaan wants to merge 3 commits into
mainfrom
feat/init

Conversation

@Chriztiaan
Copy link
Copy Markdown
Collaborator

@Chriztiaan Chriztiaan commented May 4, 2026

This PoC explores ideas for defining a template write path that should simplify implementing writes for PowerSync users. It is based on the node backend and client demos.

The core shift in this PoC is moving the "translation problem" from the client to the server edge. Right now, every developer has to write their own bespoke uploadData handler that fetches CRUD ops, maps types, talks to their backend, and classifies errors. This PoC says: what if the client just sends the raw CRUD data over the wire, and a standardised server-side stack handles everything from there? The backend includes generated endpoint handler code (via OpenAPI), a mechanism for mapping sqlite crud data to the format of a source database, and a persister for each support source database.

This is essentially a foundation layer, it defines the protocol with the happy path in mind, and both the mutator example (PoC 2) and the Supabase edge function approach (PoC 3) are described as things that can ride on top of it. We also still need to improve the implementation detail at this level in terms of interface definitions and hooks for supporting custom logic on every layer, as well as advanced tools like dead letter queues.

Adding OpenAPI codegen means that some of the implementation can be spread to new languages/platforms without reimplementing the wire code each time

Screenshot 2026-05-04 at 15 39 41

AI disclosure

This PR was created with the help of Claude Code. Help constitutes assistance in research, planning, and rough outline of implementation. Beyond having a hand in the implementation, I have also manually tested this work.

@Chriztiaan Chriztiaan changed the title (feat): Initial PoC feat: Initial PoC May 13, 2026
await transaction.complete(result.checkpoint);
break;
case 'fatal_error':
console.error('Fatal error:', result.failedOperation?.error_code, result.message);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fatal errors should also call transaction.complete().

Copy link
Copy Markdown
Collaborator Author

@Chriztiaan Chriztiaan May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that the client doesn't get stuck. That would mean we lose the data, unless we have a dead-letter queue on the backend?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. The assumption is that if it's a "fatal" error as opposed to "retryable", there is nothing we can resolve by retrying, so the only option is discarding the data.

FWIW, a dead-letter queue on the client could be another option.

Comment on lines +83 to +84
const cp = await this.options.transport.putCheckpoint(this.options.userId, this.options.clientId);
result.checkpoint = cp.checkpoint;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write checkpoints make up a big topic on its own - see https://github.com/orgs/powersync-ja/discussions/317

We probably want to finalize that before implementing a new pattern around custom write checkpoints here.

One specific thing to note is that creating a new write checkpoint after every transaction can add a lot of overhead when there are many small transactions - ideally it should only be done once at the end of the queue. But the current uploadData API is not really designed well for that appraoch.

transport: {
async postTransaction(body) {
const { data } = await client.POST('/api/data', { body });
if (!data) throw new Error('No response from /api/data');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should check the specific error response rather, like in putCheckpoint.


this._clientId = await database.getClientId();
const writeClient = await this.getWriteClient(database);
const result = await writeClient.processTransaction(transaction);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple error paths here:

  1. Error is returned, which can be fatal_error or retryable_error.
  2. Error is thrown, which should always be retryable.

Thrown errors can include network errors, gateway errors, db errors - anything not producing a valid response.

It may be worth having returned retryable_error use the same path as thrown errors, to reduce the cases the connector has to handle. For example, if the client throws those errors, we can remove the case 'retryable_error' below.

It's not important though, as long as the different cases are properly documented. Assuming every app is not going to provide a custom connector like this anymore, that logic can also be in the connector itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants