Skip to the content.

SyncLane

SyncLane

CI License: Apache 2.0 .NET 10 Tested on PostgreSQL 14 to 18 SyncLane MCP server on Glama

Sync jobs against other people’s APIs, from one PostgreSQL table you own. Every job is a row: its window, its cursor, its attempts, its error.

If your application pulls orders, products or anything else from an external API for many accounts, it needs the same things every time: load two years of history in slices, pick up what is new every few minutes, continue after a crash instead of starting over, back off when the other side says “slow down”, never hit one account’s limit from two workers at once, and send data back in order. SyncLane is a .NET library that does exactly that, inside your process, with no dependency beyond Npgsql and the Microsoft.Extensions abstractions.

SyncLane's architecture: the PostgreSQL schema with the jobs table and the indexes that carry the guarantees; the planner, lease, page loop, failure policy, rate budgets, change feed, instances and monitor inside your application; the recipe pipeline of SyncLane.Http; their APIs and your tables; and what it promises.

How a job runs, from the planner to a saved cursor and every way back when something fails (How it works says it in words):

How a job runs: plan, take, run a page, save the cursor and complete; a failed page waits and continues from its cursor, steps aside after the fifth try and waits for an operator after one more; a worker that stops hands its job back, one that dies loses it to another slot when the lease runs out; and a 429 pauses the account's budget for every instance.

Why

Hangfire, Quartz and the like are good at “run this method at that time”. A sync job is a different animal. It has a range of time it covers, a position inside that range, and a neighbour it must not overlap with. When you put that on top of a general scheduler, the interesting state ends up somewhere you cannot see: in serialized arguments, in a second table of your own, or in a lock.

SyncLane keeps that state where you can read and change it:

What it aims to be

SyncLane does not try to be a scheduler, a workflow engine or a data platform. Hangfire, Quartz and cron services run anything on time, and they do it well. SyncLane aims to be the small, dependable piece you add when your application pulls data from someone else’s API:

Quick start

dotnet add package SyncLane
dotnet add package SyncLane.Http             # recipes instead of handlers
dotnet tool install --global SyncLane.Cli    # synclane init, test and mcp

With a recipe

For an API that lists JSON records page by page, you write no request code. Give your AI assistant synclane mcp and a curl that works, and it writes the recipe, checks it and runs it for two pages (docs/ai.md); or run synclane init and synclane test yourself (docs/recipes.md). Then:

builder.Services.AddSyncLane(lane =>
{
    lane.ConnectionString = builder.Configuration.GetConnectionString("Postgres")!;
    lane.AddQueue("shops", queue =>
    {
        queue.Owners<ConnectedShops>();
        queue.Windowed<HttpRecipeHandler>("orders", horizon: TimeSpan.FromDays(365), slice: TimeSpan.FromDays(7), every: TimeSpan.FromMinutes(15));
    });
});

builder.Services.AddSyncLaneHttp(http =>
{
    http.Credentials<ShopCredentials>();   // your ICredentialStore: credentials stay in your own storage
    http.Recipe("orders", File.ReadAllText("recipes/orders.jsonc"))
        .WriteToPostgres("shop_orders", table => table.VersionedBy("$.updated_at"));
});

WriteToPostgres creates the table and keeps one row per account and record; a page that runs twice changes nothing. Your own tables take an IRecordSink. Paging, OAuth 2.0 and other auth, rate limits, retries and resuming are the recipe’s and SyncLane’s job.

With a handler

For anything a recipe does not cover (multi-step reports, GraphQL, your own client), a handler does one page and says where the next one starts:

lane.AddQueue("shops", queue =>
{
    queue.Owners<ConnectedShops>();
    queue.Windowed<OrderHandler>("orders", horizon: TimeSpan.FromDays(730), slice: TimeSpan.FromDays(30), every: TimeSpan.FromMinutes(15));
});

public sealed class OrderHandler(ShopApi api, OrderStore store) : IJobHandler
{
    public async Task<JobPage> RunPageAsync(Job job, CancellationToken cancellationToken)
    {
        var page = await api.GetOrdersAsync(job.Owner, job.WindowStart, job.WindowEnd, job.Cursor, cancellationToken);
        await store.UpsertAsync(page.Orders, cancellationToken);
        return new JobPage(page.NextCursor, page.Orders.Count);
    }
}

Either way, an owner source

It tells the planner who is connected. The key never changes; the lane groups owners that share a rate limit; the name is what the monitor shows and searches.

public sealed class ConnectedShops(AppDb db) : IOwnerSource
{
    public async Task<IReadOnlyList<JobOwner>> GetOwnersAsync(string queue, CancellationToken cancellationToken) =>
        await db.Shops.Where(shop => shop.IsConnected)
            .Select(shop => new JobOwner(shop.Id.ToString(), shop.SellerId, shop.Name))
            .ToListAsync(cancellationToken);
}

That is the whole integration. The table is created at start-up, the planner runs once a minute and the workers start pulling. Every other setting has a default you can leave alone (docs/configuration.md). To add it to an existing application step by step, with the questions to settle first, follow Integrating.

What do I use for…

Getting data sooner

I want Use
An account’s new data now, for a webhook or a “refresh” button monitor.SyncNowAsync(queue, owner, type): a burst of calls is one fetch
One job to run before everything else NewJob.Priority = JobPriority.Urgent
A new account’s history to load before the others Priority = JobPriority.High on its JobOwner, in the owner source
An account’s waiting jobs moved forward once, by an operator monitor.PrioritizeOwnerAsync(queue, owner)
An account planned the moment it connects, not at the next round syncLane.PlanAsync(queue, owner)

Stopping and repairing

I want Use
A queue or an account stopped at once, for a while monitor.PauseAsync(queue, owner, reason, until: ...), then ResumeAsync
No more jobs for an account that disconnected syncLane.CancelAsync(queue, owner, reason), and leave it out of the owner source
Everything about an account gone for good syncLane.ForgetOwnerAsync(queue, owner)
One failed job tried again, from where it stopped monitor.RequeueJobAsync(id); every job with one error code: RequeueByCodeAsync
A window fetched again from its first page monitor.RestartJobAsync(id)
One job never to run, so the jobs behind it go on monitor.SkipJobAsync(id, reason)
An API called more gently for a while monitor.LimitBudgetAsync(budget, key, limit, per, reason, until: ...)
An application’s syncing stopped or started, without a deploy monitor.SetSwitchAsync(application, role, runWorkers, runPlanner, reason): kept in the database, read by every instance when it starts
Web instances kept idle while a worker of the same build syncs SyncLane__Role=worker in the worker’s environment, and a switch per role (switching)
Several applications on one database, told apart SyncLane:Application, a name of its own in each, and queue names that start with it

Every operator call is logged with who and why, and is also on HTTP with SyncLane.AspNetCore (docs/monitoring.md).

Sending data out

I want Use
Each delivery sent once, even if asked twice NewJob.DedupKey, such as $"movement:{id}"
One account’s deliveries in order, a failed one holding the rest queue.Ordered = true (ordered queues)
The handler and the monitor to know who asked NewJob.RequestedBy
The handler handed what it must send, instead of looking it up NewJob.Arguments, read as job.Arguments
The latest request for a key to win, whether the earlier one waits, failed or completed syncLane.EnqueueOrReplaceAsync(newJob)
A delivery that got through some other way closed without a run syncLane.CompleteAsync(queue, owner, type, keys)

What it promises

Limitations

Read on

The same pages, as a website: synclane-dev.github.io/synclane.

   
Integrating Adding SyncLane to an existing application from A to Z, written so you can hand it to an AI assistant
How it works The table, a job’s life, the statements and the indexes behind the guarantees
Planning History, slices, periods and overlap, and why
Recipes Every part of a recipe; with an AI assistant
Working with jobs Every call, results and errors, priorities, rate budgets in a handler
Watching it run The monitor, live changes, HTTP, metrics, health checks
Configuration Every setting, and settings per environment
Operations Repairs, ordered queues, poolers, several instances and applications, the schema
Error codes Every code with its cause and fix
Production trial The checklist for a first run on something that may fail
The demo Four pretend shop accounts, with retries and a broken page, in Docker

Project status

Version 0.12. Before 1.0 a minor version may still change the API; every change is listed in CHANGELOG.md. The design comes from a job system that has synced external APIs for many accounts in production; this repository is a clean, general rewrite with its own tests, run on PostgreSQL 14 to 18 and through PgBouncer, but this code has not yet run in production itself. Try it on something that is allowed to fail first.

Development

dotnet build
SYNCLANE_TEST_DB="Host=localhost;Username=postgres;Database=synclane_test" dotnet test

Without SYNCLANE_TEST_DB the PostgreSQL tests are skipped. Contributions are welcome; see CONTRIBUTING.md. To report a vulnerability, see SECURITY.md.

Your responsibility

SyncLane is a library. It runs inside your process, with the credentials you give it, against the database and the destinations you choose. It sends nothing to the SyncLane authors: there is no telemetry, no license check that calls home and no hosted service in between. Your data never passes through anyone but you.

That also means the decisions are yours. When you use SyncLane, you are responsible for:

Anything in this repository that describes a third-party API, including the demo and any example, is an illustration written by contributors. It is not a statement by the provider and may be out of date. Check the provider’s own documentation before you rely on it.

License

Apache License 2.0. The software is provided on an “AS IS” basis, without warranties or conditions of any kind, and no contributor is liable for damages arising from its use; sections 7 and 8 of the license state this in full.

SyncLane is free to use, with no registration, account or paid edition, and it calls no host of its own: no telemetry, no license check, no update check.

SyncLane is an independent open-source project. It is not affiliated with, endorsed by or supported by the PostgreSQL project or any API provider.