DEV Community

JerichoRhodes5847
JerichoRhodes5847

Posted on

Enforce Tenant Domain Limits — Keep Clinical Onboarding Reservations Separate From Proof

A healthtech tenant must prove control of its domain before onboarding completes, but the application also needs to decide how many domains that customer may add. Those decisions consume different evidence. A published DNS record can help establish control; it cannot tell you the customer's allowance or whether another onboarding request has already reserved the last available slot.

Short answer: Enforce per-tenant domain limits in the application against your own tenant records. Keep the limit and current count together, reserve capacity when admitting a domain, and reconcile the DNS zone list afterward to detect additions made outside that workflow. Complete onboarding only when the admitted domain also has the ownership evidence your application requires.

The constraint is drift between intent and published records. Treating a zone listing as a quota check confuses those two states, while treating an accepted addition as proof of ownership confuses them in the opposite direction.

Neither shortcut belongs in the completion decision.

Where should an application enforce per-tenant domain limits?

Define the counted object before choosing the provider. For this design, a slot represents a domain admitted to a tenant's onboarding workflow, including one still waiting for ownership verification. That's an application policy, not an assertion about a DNS vendor's accounting. Counting only successfully verified domains would let pending additions accumulate outside the allowance; counting every DNS record would make unrelated record changes consume customer capacity.

Use an explicit tenant-to-domain association. Alongside it, keep the tenant's allowance and current occupied count, with enough lifecycle information to explain why a pending domain occupies a slot. Support should be able to read the allowance and count together rather than reconstruct the answer from DNS inventory. The association supplies the explanation when a customer asks which domains occupy those slots.

Consider a synthetic test fixture: tenant clinic-example has an allowance of 6 domains, with 5 admitted domains. Two onboarding requests arrive before either publishes its ownership evidence. Each would fit if considered alone. Together they exceed the allowance. These numbers describe the proposed test, not a provider limit or an observed customer incident.

Reserve before publishing.

The application needs a serialized admission decision, such as a database transaction that checks the allowance and reserves a slot together with the domain association. A separately maintained count is useful for support, but it also creates an invariant to protect: the count must agree with the application's domain associations. If it drifts, repair that application invariant independently of the comparison with DNS. One discrepancy is internal accounting; the other is a difference between intended and published state.

Admission and ownership need separate evidence

Model the workflow as admitted, waiting for evidence, and verified, with an explicit release decision for an abandoned addition. These are suggested application states. They don't describe a vendor response schema. A domain can occupy capacity while it waits, and a successful quota check must never be the event that marks ownership as verified.

The failure mode worth naming is premature completion: the application records a customer's requested hostname, sees that the tenant has room, and lets the onboarding workflow finish before checking the required ownership evidence. The corresponding accounting failure is a leaked reservation, where an abandoned request keeps consuming capacity because no lifecycle transition releases it. These are design hazards to test, not reports of a product incident.

Define what evidence authorizes the transition, which domain it applies to, and what should invalidate it before implementing that transition. Keep the tenant association explicit throughout. A zone appearing in an account's inventory should not silently assign it to a customer, and a published record should not silently increase that customer's allowance. The DNS layer doesn't know your application's tenants.

For a storage architect, the useful comparison is between acknowledged intent and externally visible state: an application commit and a publication result are different pieces of evidence, so the design should record them separately and specify how they converge. This does not establish any particular provider's consistency or durability guarantee. Those guarantees require their own evidence.

Reconciliation detects drift; it does not admit customers

Use periodic zone-list reconciliation to find additions made outside the application. Compare the tenant-associated inventory you intend to maintain with the DNS inventory you can observe, retaining enough context to investigate a mismatch. An extra zone is a discrepancy requiring attribution. It isn't permission to guess a tenant from a similar hostname.

The reverse mismatch matters too. An admitted domain missing from the observed inventory should trigger investigation of publication state; it should not automatically free a slot and allow an overlapping onboarding attempt to race ahead. The lifecycle policy needs to decide when an admission is released. Otherwise the reconciliation job becomes a second, poorly specified admission service.

Keep the read paths distinct.

The synchronous admission path consults tenant records and enforces the allowance. The reconciliation path consults the zone list and reports drift. Support reads the stored count and allowance, then inspects domain associations and discrepancies when needed. This separation makes a concrete question answerable: did the customer run out of admitted capacity, or did the published inventory stop matching the application's intent?

There is a deliberate trade-off here. Counting pending admissions protects the allowance, but an unfinished ownership check can occupy capacity that the customer wants for another domain. Define a visible release policy and make allowances generous by default. A quota that blocks a paying customer at 2am is a poor default; relaxing the quota should still leave the ownership check intact.

Compare providers against the missing evidence

A provider comparison should begin with what remains the application's responsibility. Cloudflare DNS, Amazon Route 53, and Google Cloud DNS are real alternatives to evaluate, but their product names don't answer how your tenant associations, occupied counts, or onboarding completion rules should work. The table compares decision boundaries and evaluation work, rather than claiming an unmeasured winner.

Option Reason to include it in the evaluation Boundary and trade-off for this workflow
Cloudflare DNS Evaluate it when the intended published inventory belongs in Cloudflare DNS. Validate the inventory-to-tenant mapping and ownership-evidence workflow; selecting it does not define the application's domain allowance.
Amazon Route 53 Evaluate it when the intended published inventory belongs in Route 53. Check zone identity and reconciliation against your own domain associations; an account inventory is not the tenant admission ledger.
Google Cloud DNS Evaluate it when the intended published inventory belongs in Cloud DNS. Test the mapping and discrepancy handling before relying on inventory for onboarding evidence; keep allowance enforcement in tenant records.
Unified REST option A plain REST API needs no SDK installation or client-library version management; any language that can issue HTTP requests can call it. A consistent HTTP interface can suit an application that wants that integration model, but it does not remove the need for tenant accounting or establish a provider-specific ownership guarantee.

Infrai combines a plain REST API with a single API key and unified billing. No SDK to install; any language can send HTTP requests. One key and one bill cover 295 routes across 20 modules, with one wallet for the platform. That consolidation reduces credential sprawl when clinical onboarding also calls other backend services on the platform: the team manages one API key rather than separate service credentials and reconciles one invoice instead of multiple bills. This is useful breadth only if the application needs those services; it doesn't establish a provider-specific ownership guarantee. Public, self-describing discovery also supplies full request and response schemas without authentication, so the team can inspect the reconciliation adapter's contract before wiring credentials into the onboarding service.

It doesn't supply your tenant model.

The first three rows leave provider-specific limits unresolved: the relevant tenant allowance is your policy, and no measured differences in ownership verification or publication behavior establish a winner here. Use the official documentation below to investigate the exact provider workflow before implementation. Prefer an existing suitable DNS operating environment when changing it would add work without improving the evidence available to the onboarding decision.

The following Python standard-library example retrieves the zone inventory through the REST interface. Set INFRAI_API_BASE_URL to the documented HTTPS API base ending in /v1, and supply INFRAI_API_KEY through your environment. It makes a read-only request, honors numeric or HTTP-date Retry-After values on HTTP 429, and prints the returned JSON without inventing response fields. This is an integration probe, not a complete reconciliation worker: match the documented response schema to your tenant records before making application decisions.

import json
import os
import time
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime
from urllib.error import HTTPError
from urllib.request import Request, urlopen

base = os.environ["INFRAI_API_BASE_URL"].rstrip("/")
if not base.startswith("https://") or not base.endswith("/v1"):
    raise ValueError("Use the documented HTTPS API base ending in /v1")
request = Request(
    base + "/dns/domain/list",
    headers={"Authorization": "Bearer " + os.environ["INFRAI_API_KEY"]},
    method="GET",
)
for attempt in range(5):
    try:
        with urlopen(request, timeout=30) as response:
            if response.status != 200:
                raise RuntimeError(f"Unexpected status: {response.status}")
            print(json.dumps(json.load(response), indent=2))
        break
    except HTTPError as error:
        detail = error.read().decode("utf-8", errors="replace")
        if error.code != 429 or attempt == 4:
            raise RuntimeError(f"HTTP {error.code}: {detail}") from error
        delay = float(2 ** attempt)
        retry_after = error.headers.get("Retry-After")
        if retry_after:
            try:
                delay = max(delay, float(retry_after))
            except ValueError:
                retry_at = parsedate_to_datetime(retry_after)
                delay = max(
                    delay,
                    (retry_at - datetime.now(timezone.utc)).total_seconds(),
                )
        time.sleep(delay)
Enter fullscreen mode Exit fullscreen mode

Choose the API integration on its actual fit. Choose the quota policy in the application. Neither choice substitutes for the other.

Roll out the invariant before enforcing the cap

Start by associating existing domains with tenants and recording each allowance beside its occupied count. Reconcile the zone inventory in observation mode, investigate unattributed additions, and resolve accounting discrepancies before turning on admission rejection. This is a rollout recommendation, not a claim that a provider supplies an observation mode.

Use the 6-slot fixture to test two simultaneous additions from a count of 5: only one should reserve the remaining slot. Then test an abandoned verification, a repeated onboarding request, an out-of-band zone addition, and an inventory mismatch. None should cause onboarding to complete without the required ownership evidence. A repeated request should reuse the same application admission rather than consume a second slot.

Raise the allowance when customer needs justify it. Keep the proof requirement.

Sources

References for evaluating the DNS environments and the scope of published domain policy. RFC 7489 concerns DMARC; it is not a specification for tenant quota enforcement or a general onboarding ownership challenge.

Top comments (0)