DEV Community

eliasfischer8351
eliasfischer8351

Posted on

Small SaaS Europe-US: Public HTTPS Webhook Push, Queue Subscribe, or Polling Worker

Short answer: for a small SaaS that must delay a media renewal reminder until a business deadline, put the deadline and its idempotency key in durable application state, then choose public HTTPS webhook push when the web application already owns ingress, or a polling worker when a private consumer should own delivery. The important decision is who can prove, after a retry, that the reminder was committed once and why.

This is an architecture decision record about clocks and failure boundaries. A queue does not know that a renewal deadline was moved, a subscription was cancelled, or a notification became legally inappropriate while it was waiting. Those are business facts. The transport only moves a request to inspect them.

For a media service spanning Europe and the US, store the intended deadline with an explicit time-zone interpretation and a canonical UTC instant. Do not let a worker silently reinterpret “09:00 Europe” using the machine’s local clock. The record should also carry the subscription version, operation key, current status, and an append-only audit event for each meaningful decision.

Deadline data needs a governance owner

The first invariant is straightforward: one business operation key can create one durable reminder outcome. The second is less obvious: a delayed task is an instruction to re-evaluate current state, not a license to replay stale state. If the account owner changes the billing contact after scheduling, the worker must read the current record before sending anything.

The scheduler should write the reminder intent and its audit entry before handing work to a queue. An outbox or equivalent transaction boundary prevents the database from saying “scheduled” while the enqueue operation vanished. The consumer then records sent, skipped, expired, or retryable with the reason and attempt metadata. This makes reconciliation possible when a customer asks why a reminder did or did not arrive.

The deadline is the anchor. The message is a disposable delivery attempt.

One row should answer the customer-support question without reconstructing an entire trace.

Boundary What it owns What it must not assume
Business database Deadline, subscription version, operation key, audit state That delivery succeeded because a task was created
Outbox or queue Durable handoff and delivery attempts That the payload is still current
HTTPS receiver or polling worker Validation, state re-check, notification decision That acknowledgement means an email was observed by a person
Notification provider External send attempt and provider response That a network timeout proves the send failed

The choice between push and polling is therefore downstream of the record design. If the record cannot explain the result, changing the consumer shape only changes where the ambiguity appears.

Three failure sequences around one deadline

Run the design through failure sequences before debating the consumer. Suppose a renewal is scheduled for 09:00 in Europe, the subscription is cancelled at 08:59, and a worker receives the original task at 09:01 after a lease timeout. The correct outcome is a recorded skip against the current subscription version. If the notification provider accepted the request at 09:00 but the response disappeared, the correct outcome is reconciliation by operation key, not a blind second send. If the process dies before the database commit, the task must remain retryable. These cases are different even though an operator may first see the same symptom: “the attempt did not finish.”

The critical test is not “did the queue deliver?” It is “can the audit trail explain the business effect?”

Neither push nor polling promises exactly-once execution. The practical target is an exactly-once business effect around an at-least-once delivery mechanism. That distinction belongs in the design record and in the test plan.

Here is the narrow business boundary I would keep identical behind either adapter. The store implementation must make the key check, state transition, and audit insert one transaction; the interface deliberately does not pretend that a queue acknowledgement is part of that transaction.

package reminder

import (
    "context"
    "crypto/sha256"
    "encoding/hex"
    "errors"
    "fmt"
)

type Reminder struct {
    OperationKey     string
    SubscriptionID   string
    SubscriptionVer  int64
    DeadlineUTC      int64
    Payload           []byte
}

type Store interface {
    // Apply records the outcome and audit event atomically for a new key.
    Apply(context.Context, Reminder, string) (duplicate bool, err error)
}

func Process(ctx context.Context, store Store, reminder Reminder) error {
    if reminder.OperationKey == "" {
        return errors.New("missing operation key")
    }
    if reminder.SubscriptionID == "" || reminder.SubscriptionVer <= 0 {
        return errors.New("invalid subscription identity")
    }

    digest := sha256.Sum256(reminder.Payload)
    duplicate, err := store.Apply(ctx, reminder, hex.EncodeToString(digest[:]))
    if err != nil {
        return fmt.Errorf("apply reminder decision: %w", err)
    }
    if duplicate {
        return nil
    }
    return nil
}
Enter fullscreen mode Exit fullscreen mode

The public handler calls Process before acknowledging the delivery. The polling adapter does the same before releasing its lease. If the process exits after the database commit but before acknowledgement, the next delivery finds the operation key and records no second business effect. If it exits before the commit, a retry is necessary. The notification send itself needs a provider-side idempotency contract or a durable send ledger; otherwise a database guard alone cannot prevent two external messages after an uncertain timeout.

Should a small SaaS choose public HTTPS webhook push or queue subscribe?

Public HTTPS webhook push fits a SaaS whose existing application boundary already terminates TLS, authenticates requests, limits concurrency, and has a clear deployment owner. The handler can accept an envelope, verify its signature or equivalent authentication, load the current reminder, and enqueue or commit the next step. It should return success only after the durable handoff is complete. A lost response then causes a duplicate request, which is expected rather than exceptional.

A polling worker fits a private network, a consumer that should not accept inbound traffic, or a team that already operates a supervised background process. Pulling gives that process direct control over lease duration, concurrency, backoff, and shutdown. It also gives the team more machinery to observe: queue age, lease expiry, attempt count, and the age of the oldest unprocessed deadline.

The trade-off is operational ownership. Public push reduces worker lifecycle code but puts burst control and endpoint availability in the web tier. Polling keeps the receiver private but makes leases, shutdown, and consumer capacity the team's responsibility. Public HTTPS push is not suitable when the processing transaction depends on a private network that the web tier cannot reach; stick with polling there. Polling is not suitable when nobody can supervise a long-running consumer; use the already-operated HTTPS boundary instead.

A late deadline needs a policy

A retry policy needs two clocks: the delivery clock and the business clock. Exponential backoff may be reasonable for a temporary capacity response, but it is not automatically reasonable after the renewal deadline has passed. At that point the system should compare the current time with the permitted send window and record an explicit expiration or escalation decision.

Separate failure classes. An invalid signature or malformed payload is a quarantine decision. A rate limit is a capacity decision and should preserve the task while slowing attempts. A network timeout is ambiguous: the downstream system may have accepted the notification, so retrying requires an idempotency key or reconciliation step. A cancelled subscription is a business decision, not a transient transport error.

I've seen teams reduce all of these to retry = true, which is how a small reminder service acquires a large audit problem. Keep the original payload digest, response class, attempt number, next-attempt time, and correlation ID. The record should say whether the system sent, skipped, expired, or needs review.

Short answer, operationally: the component closest to the failure should own the retry state, while the business database owns the decision that retries must not duplicate. A public endpoint may own ingress retries; a worker may own leases; neither should invent a second source of truth for the reminder.

Roll out the clock in observable steps

Run the design through failure sequences rather than counting lines of setup code. A useful test set includes duplicate deliveries with the same key, two different payloads using one key, a crash before commit, a crash after commit and before acknowledgement, clock skew around the Europe-US deadline, cancellation after scheduling, and a notification provider timeout after acceptance. Start with a synthetic reminder whose deadline is close enough to exercise the boundary, then replay the same operation key through the real adapter while recording every state transition. Compare the audit row with the queue attempt record and the provider response, and make the test fail if the second delivery changes the outcome, if a stale subscription version sends a notification, or if a retry loses its original payload digest. This is more useful than a dashboard screenshot because it tests the relationship between records that operators will later need to reconcile.

No magic.

The result should be observable without opening application logs by hand. Emit one correlation ID through scheduling, outbox publication, queue delivery, state evaluation, and notification attempt. Measure deadline lateness and retry age. Alert when old work accumulates, when leases expire repeatedly, or when the audit state has no matching delivery record.

The rejected default is “poll everything because polling is easier.” Polling is a poor fit when no one owns the worker runtime, when queue age cannot be monitored, or when the service needs a very small public surface and already has a well-operated HTTPS tier. Public push is unsuitable when the receiver must remain private, inbound authentication cannot be enforced at the edge, or the processing transaction depends on a network only the worker can reach.

Use a queue subscription when delivery should be brokered and the consumer can handle repeated attempts. Use a polling worker when the consumer needs explicit lease and concurrency control. Use a workflow engine when the reminder becomes a chain of waits, dependencies, and compensating actions. Your mileage may vary: the correct answer follows from ownership of the deadline, retry, and audit evidence, not from the transport label.

References

Top comments (0)