IMD SolutionComputing LibraryShop main store

How-to

Buffer SQL stored procedure calls behind Ignition WebDev endpoints

Edge computing and IIoT Published 6 min read

Short answer

Acknowledge a WebDev write only after the record is durably buffered, never while it waits on SQL Server. Keep synchronous calls for reads with one end-to-end deadline, put writes that need no immediate result through a durable queue with idempotency keys, and check any timed-out call by key before retrying it.

On this page
  1. Split every call by what its caller needs
  2. Sizing the synchronous budget for 5 gateways at 20 calls per minute
  3. Protect the synchronous read path
  4. Build the asynchronous write path
  5. Choose the buffer that fits your gateway layout
  6. Check a timed-out write before retrying it
  7. What this buys each case
  8. Questions asked

A WebDev endpoint that waits on the database holds a gateway session for the whole wait, so a stalled SQL Server turns a burst of calls into session and connection-pool exhaustion. The decision is simple: any stored-procedure write that does not need its result in the HTTP response gets acknowledged only after the record is durably buffered, and only reads stay synchronous. This article sets up that split, sizes the synchronous budget, and defines what a buffer acknowledgment does and does not mean.

The Web Dev module lets you script directly against the web server inside the Ignition gateway, so the endpoint pattern in this article applies to Ignition 8.1 and 7.9 gateways alike; the buffering design around it is yours to build. The settings named below are the kinds of limits to look for in your database driver, connection pool and load balancer; their exact names depend on the products and versions you deploy.

Split every call by what its caller needs #

  1. Classify each endpoint operation at design time. A read whose caller needs the procedure result in the response stays synchronous. An insert or command that only needs to happen goes on the asynchronous buffer path. Do not decide per request; decide per operation key.

  2. Give every request one end-to-end deadline that the caller sees, then set shorter internal limits for connection-pool acquisition and SQL execution inside it, so the gateway retains time to return a controlled failure instead of being cut off mid-response.

  3. Cap concurrent synchronous requests separately from asynchronous workers, and reserve database connections for each workload so buffered writes cannot starve reads.

  4. Reject new work at a bounded queue or concurrency limit instead of admitting an unlimited backlog. A full buffer is a fast, visible failure; an unbounded one is a slow collapse of the whole gateway.

  5. Require an idempotency key from any client that may retry, and log a correlation identifier at ingress that travels with the queue record, the database transaction and the response.

Sizing the synchronous budget for 5 gateways at 20 calls per minute #

The inputs below are an illustrative design point, not a specification: five gateways behind a load balancer, 20 stored-procedure calls per minute per gateway, a mean synchronous call that occupies its session for 3 seconds (0.5 s pool acquisition plus 2.5 s SQL execution), and a target of keeping average session occupancy below 100 percent with headroom for bursts.

The rule is Little's law: the average number of simultaneously occupied sessions equals the arrival rate multiplied by the mean time a request holds the session.

Arithmetic for one gateway:

  • Arrival rate: 20 calls per minute = 0.333 calls per second.
  • Occupied sessions: 0.333 calls per second x 3 seconds = 1.0 session on average.

Arithmetic for the outage case, where calls run to a 10-second end-to-end deadline instead of completing in 3 seconds:

  • Occupied sessions: 0.333 calls per second x 10 seconds = 3.3 sessions per gateway.
  • Across five gateways: 3.3 x 5 = 16.5 sessions holding open against a dead database.

The decision: 20 calls per minute per gateway is sustainable while the database is healthy, but a database stall multiplies held sessions by 3.3x within one deadline period and client retries arrive on top of that. Above roughly 30 calls per minute per gateway at this service time, or whenever the database can stall, route the writes to the buffer path and keep only reads synchronous. If your connection pool grants 20 connections, reserve a share for reads; 16.5 stalled writers plus retries will otherwise take the whole pool and starve the synchronous path too.

Protect the synchronous read path #

  • Stop admitting calls while database health checks fail or the failure rate crosses the threshold you selected; reject fast instead of holding sessions open.
  • Cancel the database work when the caller abandons the request, where the driver and database support cancellation, and treat a cancellation as an uncertain outcome until you check the transaction state.
  • Verify the path before tuning scripts: link state, routing, name resolution, load-balancer health checks and database reachability from every gateway. A WebDev timeout cannot fix an unreachable backend or an exhausted pool.

Build the asynchronous write path #

  1. Authenticate, authorize, and validate before accepting anything: payload size, parameter names, types, ranges and nullability against the mapped procedure.

  2. Translate an approved operation key to a fixed stored procedure. Never execute SQL text or a procedure name taken from the payload.

  3. Persist one durable queue record containing the operation, validated arguments, caller identity, creation time, idempotency key, attempt state and correlation identifier.

  4. Acknowledge the client only after the buffer confirms durable persistence. The acknowledgment means accepted for processing, not committed to SQL. A bounded buffer that survives a restart is what makes the word durable mean something; the same principle of bounded, persistent buffers applies to edge error logs on resource-limited devices, as described in the guide on why ESP32 error logs need bounded buffers and durable storage.

  5. Run a bounded number of workers that claim records, execute parameterized procedure calls, and commit the database transaction before marking the record complete.

  6. Classify failures: retry transient connectivity and availability errors with delayed backoff; move validation errors, unknown operations and repeatable procedure failures to a dead-letter state for review.

  7. On worker or gateway restart, recover claimed-but-incomplete records. The database side must be idempotent, either by enforcing the idempotency key inside the transaction or by checking a ledger of applied keys first.

Choose the buffer that fits your gateway layout #

A gateway-local SQLite file is the right buffer for a single gateway or an explicitly node-affine design: simple, local, and it survives a database outage for as long as its retention allows. Behind a load balancer it fragments the backlog across nodes, a retry can land on a gateway that never saw the original request, and losing a node loses its buffered records. For paired or load-balanced gateways, use a shared durable queue that any worker can replay after recovery, with the idempotency and dead-letter rules above. The trade-offs are the same ones that decide between local and shared buffering on MQTT store-and-forward backfill after a connection outage. Event Streams with an HTTP source can close the session and buffer for you, but do not assume its persistence, ordering, replay or dead-letter behavior; configure and test each of those before trusting it, the way you would verify historian store-and-forward completion before calling data stored.

Check a timed-out write before retrying it #

A timeout does not prove the transaction failed. The database may commit after the caller stopped waiting, and a blind retry then duplicates an insert or fires a command twice. Query by the idempotency key or correlation identifier first: committed means skip, absent means requeue once. A controlled failure response on the synchronous path should carry that identifier so the caller can ask later; retaining results by correlation identifier also lets a disconnected device collect its answer instead of depending on a single callback to a tag path. If the payload supplies a tag path for writeback, resolve it against a registered device identity rather than honoring an arbitrary route.

What this buys each case #

  • Healthy database, mixed load: reads return within the end-to-end deadline; writes are accepted in milliseconds and drained by bounded workers.
  • Database outage: writes keep being acknowledged from the durable buffer, sessions stay short, and the backlog replays in order after recovery, exactly the behavior you want from edge buffering during a database outage.
  • Database stall on a synchronous read: the caller gets a controlled failure inside the deadline instead of a pile of held sessions and a starved pool.
  • Duplicate-prone procedure after a timeout: the idempotency check prevents the second commit.

Questions asked

If a stored procedure call times out, did the database commit?

A timeout proves only that the caller stopped waiting; the transaction can still commit after the deadline passes. Treat the outcome as unknown until you query by the idempotency key or correlation identifier you stored with the request. If the commit landed, skip the call; if it did not, requeue once. Retrying blindly on a non-idempotent procedure inserts duplicate rows or fires duplicate commands.

Does a short SQL timeout alone prevent the gateway from running out of threads?

No. A statement timeout bounds only the SQL execution interval. Name resolution, TCP connection setup, connection-pool waiting, request-body handling and load-balancer idle time each have their own waiting periods. To keep sessions bounded, set a caller-visible end-to-end deadline and configure shorter pool-acquisition and SQL-execution limits inside it, then cap concurrent synchronous requests.

Is a gateway-local SQLite buffer safe behind a load balancer?

It is safe only when each gateway owns its backlog and records stay on the node that accepted them. Loss of a node also removes access to its buffered records, and load-balanced retry traffic can land on a different gateway that never saw the original request. For paired or load-balanced gateways, prefer a shared durable queue that any worker can replay.

Should the payload name the stored procedure directly?

No. Let an external payload select arbitrary SQL text or any procedure name and you have handed callers an injection surface. Map an approved operation key to one fixed stored procedure, validate its parameter names, types, ranges, nullability and maximum payload size, and reject anything else before queueing or executing the call.

Keep reading

  • Explainer

    Store-and-forward SQL buffering during MES outages

    Treat the MES requirement as a durable store-and-forward buffer, not a database mirror. Capture every record locally with its acquisition timestamp — a file for event-level data, a queue table or a local time-series store for measurement streams — and replay only what the remote SQL database has actually committed. Size the buffer from record rate, record size and outage duration; at the worked rates a 256 MB partition carries a 72-hour outage.

    Edge computing and IIoT

  • Troubleshooting

    Fix Ignition SQL Server connection faults after an upgrade

    After an Ignition 8.1.x upgrade, a faulted SQL Server connection is almost never a credentials problem: the new Java runtime disables TLS 1.0 and 1.1 (builds from 8u291), and a Microsoft JDBC driver as old as 4.0 cannot run on it. Read the Gateway exception, then patch SQL Server to TLS 1.2 per KB3135244 or replace the driver; the reported working pair was 9.4 in place of 4.0.

    Edge computing and IIoT

  • How-to

    How to log Ignition tags every 15 minutes to a database

    To capture Ignition tag values on a strict 15-minute schedule, use a scheduled SQL Bridge transaction group that inserts a snapshot row into a database table, then point the report's query at that table. The tag historian is deadband-driven and stores asynchronously, so it cannot be set to one fixed 15-minute timestamp.

    Edge computing and IIoT