How to tender truckload freight down a routing guide: ranked carriers per lane, response windows, accept and decline handling, expiry sweeps, EDI 204 and 990 messages, and a state machine on Postgres that stays correct when responses arrive late or twice.

A shipper or broker moving contract freight tenders each load down a routing guide: the primary carrier on the lane gets the first offer at the contracted rate, and every decline or timeout moves it to the next carrier until someone accepts.
The backend has to hold that state while EDI 990 responses arrive late, twice or after a timeout already moved the load, and each step down the guide costs money. This guide builds that tendering service on Postgres.
Every rejected tender sends the load to a carrier further down the guide at a higher rate. FreightWaves reported on November 21, 2026 that primary tender acceptance in SONAR's data fell to 88.06% while the premium for the second tender climbed to 10.69%, so roughly one load in eight was already moving down the guide at a higher price in the run-up to Thanksgiving. The tender rejection index behind those numbers is built from EDI tenders and responses, which is the same traffic this service handles.
A tendering backend cannot fix the market, but it decides how fast a declined load reaches the next carrier, whether an expired offer is noticed in minutes or hours, and whether a load ever ends up with two carriers.
Response windows are set per carrier and lane in the contract, which is why they belong in the routing guide row rather than in code.
The waterfall stays consistent when a load can have only one open tender, enforced by a partial unique index on the load where the status is pending, so a decline and an expiry sweep that run at the same moment cannot both create a new tender. Tenders change state only through a conditional update that checks the tender is still pending and inside its window, which leaves a duplicate 990 or a late acceptance with nothing to update, and the next carrier is picked by a query that skips every carrier already offered the load, so the advance step is safe to retry.
Sending the 204 happens outside the database transaction, through a queue, because carriers and EDI providers fail and time out. The tender ID goes into the shipment reference, so a carrier that receives the same 204 twice after a retry can recognise it.
Encore is a backend framework with built-in infrastructure, and here that means the routing guide tables, the queue of outgoing tenders and the expiry schedule are declared in the tendering service itself and provisioned in your own AWS or GCP account. Encore creates RDS and SNS with SQS on AWS, or Cloud SQL and Pub/Sub on GCP, as the infrastructure docs describe. Logistics teams such as Pallet, which runs an event-driven logistics platform on GCP, and Quiqup build on Encore in this way.

Run in your terminal to get started locally.
The service below creates loads, records carrier responses, walks the routing guide and sweeps expired tenders, with the 204 sent by a subscriber:
// tendering/tendering.go
package tendering
import (
"context"
"errors"
"time"
"encore.dev/beta/errs"
"encore.dev/cron"
"encore.dev/pubsub"
"encore.dev/rlog"
"encore.dev/storage/sqldb"
)
var db = sqldb.NewDatabase("tendering", sqldb.DatabaseConfig{Migrations: "./migrations"})
type TenderSent struct {
TenderID int64 `json:"tender_id"`
}
// One message per tender; a subscriber turns it into an EDI 204 or a carrier API call.
var tenderSent = pubsub.NewTopic[*TenderSent]("tender-sent", pubsub.TopicConfig{
DeliveryGuarantee: pubsub.AtLeastOnce,
})
type CreateLoadParams struct {
Lane string `json:"lane"` // for example "ATL-DAL-VAN"
PickupAt time.Time `json:"pickup_at"`
}
type CreateLoadResponse struct {
LoadID int64 `json:"load_id"`
TenderID int64 `json:"tender_id"` // 0 if the routing guide had no carrier for the lane
}
// CreateLoad stores a load and tenders it to the first carrier in the lane's routing guide.
//
//encore:api private method=POST path=/loads
func CreateLoad(ctx context.Context, p *CreateLoadParams) (*CreateLoadResponse, error) {
tx, err := db.Begin(ctx)
if err != nil {
return nil, err
}
defer tx.Rollback()
var loadID int64
if err := tx.QueryRow(ctx, `
INSERT INTO loads (lane, pickup_at, status) VALUES ($1, $2, 'tendering') RETURNING id`,
p.Lane, p.PickupAt).Scan(&loadID); err != nil {
return nil, err
}
tenderID, err := advance(ctx, tx, loadID)
if err != nil {
return nil, err
}
if err := tx.Commit(); err != nil {
return nil, err
}
if err := publish(ctx, tenderID); err != nil {
return nil, err
}
return &CreateLoadResponse{LoadID: loadID, TenderID: tenderID}, nil
}
type ResponseParams struct {
Accepted bool `json:"accepted"`
Reason string `json:"reason,omitempty"`
}
// RecordResponse is called by the service that parses EDI 990s or carrier API callbacks.
//
//encore:api private method=POST path=/tenders/:id/response
func RecordResponse(ctx context.Context, id int64, p *ResponseParams) error {
status := "declined"
if p.Accepted {
status = "accepted"
}
tx, err := db.Begin(ctx)
if err != nil {
return err
}
defer tx.Rollback()
// Only an open tender can be answered, so a late or repeated response changes nothing.
var loadID, carrierID int64
err = tx.QueryRow(ctx, `
UPDATE tenders SET status = $2, reason = $3, responded_at = now()
WHERE id = $1 AND status = 'pending' AND expires_at > now()
RETURNING load_id, carrier_id`, id, status, p.Reason).Scan(&loadID, &carrierID)
if errors.Is(err, sqldb.ErrNoRows) {
var current string
if err := tx.QueryRow(ctx, `SELECT status FROM tenders WHERE id = $1`, id).Scan(¤t); err != nil {
return err
}
if current == status {
return nil // duplicate of a response we already recorded
}
return &errs.Error{Code: errs.FailedPrecondition, Message: "tender is no longer open: " + current}
} else if err != nil {
return err
}
var next int64
if p.Accepted {
_, err = tx.Exec(ctx, `UPDATE loads SET status = 'covered', carrier_id = $2 WHERE id = $1`, loadID, carrierID)
} else {
next, err = advance(ctx, tx, loadID)
}
if err != nil {
return err
}
if err := tx.Commit(); err != nil {
return err
}
return publish(ctx, next)
}
// advance tenders the load to the next carrier in the routing guide that has not had it yet,
// or marks the load for the spot market when the guide is exhausted.
func advance(ctx context.Context, tx *sqldb.Tx, loadID int64) (int64, error) {
var tenderID int64
err := tx.QueryRow(ctx, `
INSERT INTO tenders (load_id, carrier_id, rank, rate_cents, expires_at)
SELECT l.id, g.carrier_id, g.rank, g.rate_cents, now() + make_interval(mins => g.response_minutes)
FROM loads l
JOIN routing_guide g ON g.lane = l.lane
WHERE l.id = $1
AND NOT EXISTS (SELECT 1 FROM tenders t WHERE t.load_id = l.id AND t.carrier_id = g.carrier_id)
ORDER BY g.rank
LIMIT 1
RETURNING id`, loadID).Scan(&tenderID)
if errors.Is(err, sqldb.ErrNoRows) {
_, err = tx.Exec(ctx, `UPDATE loads SET status = 'spot' WHERE id = $1`, loadID)
return 0, err
}
return tenderID, err
}
func publish(ctx context.Context, tenderID int64) error {
if tenderID == 0 {
return nil
}
_, err := tenderSent.Publish(ctx, &TenderSent{TenderID: tenderID})
return err
}
var _ = pubsub.NewSubscription(tenderSent, "send-tender", pubsub.SubscriptionConfig[*TenderSent]{
Handler: sendTender,
RetryPolicy: &pubsub.RetryPolicy{MinBackoff: 15 * time.Second, MaxBackoff: 10 * time.Minute, MaxRetries: 10},
})
func sendTender(ctx context.Context, ev *TenderSent) error {
var carrierID, loadID int64
var sentAt *time.Time
if err := db.QueryRow(ctx, `SELECT carrier_id, load_id, sent_at FROM tenders WHERE id = $1`, ev.TenderID).
Scan(&carrierID, &loadID, &sentAt); err != nil {
return err
}
if sentAt != nil {
return nil // already sent on an earlier delivery
}
// Build the 204 with the tender ID as the shipment reference, so a carrier can drop duplicates,
// and hand it to your EDI provider or the carrier's API here. A returned error is retried.
rlog.Info("tender load", "tender_id", ev.TenderID, "load_id", loadID, "carrier_id", carrierID)
_, err := db.Exec(ctx, `UPDATE tenders SET sent_at = now() WHERE id = $1 AND sent_at IS NULL`, ev.TenderID)
return err
}
// Every five minutes, unanswered tenders past their response window move to the next carrier.
var _ = cron.NewJob("expire-tenders", cron.JobConfig{
Title: "Expire unanswered load tenders",
Every: 5 * cron.Minute,
Endpoint: ExpireTenders,
})
//encore:api private
func ExpireTenders(ctx context.Context) error {
rows, err := db.Query(ctx, `
SELECT id FROM tenders WHERE status = 'pending' AND expires_at <= now() ORDER BY expires_at LIMIT 200`)
if err != nil {
return err
}
var ids []int64
for rows.Next() {
var id int64
if err := rows.Scan(&id); err != nil {
rows.Close()
return err
}
ids = append(ids, id)
}
rows.Close()
if err := rows.Err(); err != nil {
return err
}
for _, id := range ids {
if err := expireOne(ctx, id); err != nil {
return err
}
}
// Republish pending tenders that were committed but never sent, so a
// failed publish after Commit cannot stall the waterfall.
return republishUnsent(ctx)
}
func republishUnsent(ctx context.Context) error {
rows, err := db.Query(ctx, `
SELECT id FROM tenders WHERE status = 'pending' AND sent_at IS NULL`)
if err != nil {
return err
}
var ids []int64
for rows.Next() {
var id int64
if err := rows.Scan(&id); err != nil {
rows.Close()
return err
}
ids = append(ids, id)
}
rows.Close()
if err := rows.Err(); err != nil {
return err
}
for _, id := range ids {
if err := publish(ctx, id); err != nil {
return err
}
}
return nil
}
func expireOne(ctx context.Context, tenderID int64) error {
tx, err := db.Begin(ctx)
if err != nil {
return err
}
defer tx.Rollback()
var loadID int64
err = tx.QueryRow(ctx, `
UPDATE tenders SET status = 'expired' WHERE id = $1 AND status = 'pending' RETURNING load_id`,
tenderID).Scan(&loadID)
if errors.Is(err, sqldb.ErrNoRows) {
return nil // answered while the sweep was running
} else if err != nil {
return err
}
next, err := advance(ctx, tx, loadID)
if err != nil {
return err
}
if err := tx.Commit(); err != nil {
return err
}
return publish(ctx, next)
}
-- tendering/migrations/1_create_tendering.up.sql
CREATE TABLE carriers (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
scac TEXT NOT NULL UNIQUE
);
-- The routing guide: carriers in order of preference for each lane, at the contracted rate.
CREATE TABLE routing_guide (
lane TEXT NOT NULL,
rank INTEGER NOT NULL CHECK (rank > 0),
carrier_id BIGINT NOT NULL REFERENCES carriers (id),
rate_cents INTEGER NOT NULL CHECK (rate_cents > 0),
response_minutes INTEGER NOT NULL DEFAULT 120,
PRIMARY KEY (lane, rank),
UNIQUE (lane, carrier_id)
);
CREATE TABLE loads (
id BIGSERIAL PRIMARY KEY,
lane TEXT NOT NULL,
pickup_at TIMESTAMPTZ NOT NULL,
status TEXT NOT NULL CHECK (status IN ('tendering', 'covered', 'spot')),
carrier_id BIGINT REFERENCES carriers (id),
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE tenders (
id BIGSERIAL PRIMARY KEY,
load_id BIGINT NOT NULL REFERENCES loads (id),
carrier_id BIGINT NOT NULL REFERENCES carriers (id),
rank INTEGER NOT NULL,
rate_cents INTEGER NOT NULL,
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'accepted', 'declined', 'expired')),
reason TEXT,
expires_at TIMESTAMPTZ NOT NULL,
sent_at TIMESTAMPTZ,
responded_at TIMESTAMPTZ,
UNIQUE (load_id, carrier_id)
);
-- At most one open tender per load, even if a decline and the expiry sweep race.
CREATE UNIQUE INDEX tenders_one_open_per_load ON tenders (load_id) WHERE status = 'pending';
CREATE INDEX tenders_open_by_expiry ON tenders (expires_at) WHERE status = 'pending';
encore run starts Postgres, applies the migration and runs the topic locally, so a test can create a load, post a decline to /tenders/:id/response and watch the second tender go out in the local traces. The cron job does not run locally, so the expiry path is tested by calling ExpireTenders directly after moving a deadline into the past, and on a deployed environment Encore runs it every five minutes with no extra infrastructure, as the cron docs explain. The Pub/Sub docs cover the retry policy and the dead-letter queue a tender lands in when an EDI provider keeps failing.
Carrier API keys and EDI provider credentials belong in Encore secrets rather than in the repository. To deploy, connect your AWS or GCP account as described in Connect your cloud account and push, and the database, topic and schedule are created in that account.
When an AI coding agent adds a spot-market step after the guide runs out, it edits advance, adds a topic for the broker integration and runs the whole waterfall locally in one change.
Best fit: Shippers and brokers that want routing guide tendering as their own service in their AWS or GCP account, with the state machine, queue and schedule in one reviewed codebase.
Test a decline and an expiry for the same tender arriving together, a duplicate 990, an acceptance one minute after the deadline, a lane with no routing guide, and a guide where every carrier declines. Replay a day of real 990s from your EDI provider against a staging environment, and check that every load ends in exactly one of covered or spot with at most one accepted tender.
A load tender is a shipper's offer of a specific shipment to a carrier at an agreed rate, usually sent as an EDI 204 Motor Carrier Load Tender or through the carrier's API. The carrier replies with an EDI 990 or an API call to accept or decline, typically within a response window set in the contract.
A routing guide lists the preferred carriers for each lane in rank order with their contracted rates. The load is tendered to the first carrier, and if that carrier declines or does not answer in time, it moves to the next one, until a carrier accepts or the guide runs out and the load goes to the spot market.
Allow only one open tender per load in the database, for example with a partial unique index on the load ID where the status is pending, and change a tender's status only with a conditional update that checks it is still pending. A decline and a timeout that race then cannot both advance the load.
With Encore you declare the Postgres database, a Pub/Sub topic for outgoing tenders and a cron job for the expiry sweep in the service code. Deploying provisions RDS and SNS with SQS on AWS, or Cloud SQL and Pub/Sub on GCP, in your own account.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.