An FDE's software is only as useful as its connections to the customer's systems. In a single engagement you may call a modern REST API with OAuth, receive webhooks, pick up nightly CSV files from an SFTP server, read incrementally from a database, and talk to a SOAP service older than some of your colleagues. This lesson covers each of those integration styles, the machine-to-machine authentication patterns that go with them, and the reliability patterns that keep integrations correct when networks fail and messages repeat: idempotency, incremental sync with watermarks, quarantines and reconciliation.
- Authenticate service-to-service with OAuth client credentials, API keys and mTLS
- Consume paginated, rate-limited APIs safely
- Receive webhooks securely with signature verification and idempotent handling
- Integrate file drops over SFTP and incremental database reads robustly
- Apply idempotency, watermarks, dead-letter queues and reconciliation
Machine-to-machine authentication
Integrations run without a person present, so they authenticate as a machine identity. The customer's identity team will usually tell you which pattern they allow; know them all.
| Pattern | How it works | Watch out for |
|---|---|---|
| OAuth 2.0 client credentials | Exchange client ID and secret for a short-lived access token at the token endpoint | Cache tokens until near expiry; request minimal scopes |
| API key | Static secret sent in a header | Rotation, storage in a vault, never in URLs |
| Mutual TLS (mTLS) | Client presents a certificate the server trusts | Certificate renewal before expiry |
| Workload identity | Cloud or Kubernetes identity federated to the target | Best option when available: no static secret |
| Signed requests | Request signed with a shared secret or key (HMAC) | Clock skew and canonicalisation details |
import os
import time
import httpx
_token = {"value": None, "expires": 0.0}
def access_token() -> str:
if _token["value"] and time.time() < _token["expires"] - 60:
return _token["value"]
r = httpx.post(os.environ["TOKEN_URL"], timeout=10, data={
"grant_type": "client_credentials",
"client_id": os.environ["CLIENT_ID"],
"client_secret": os.environ["CLIENT_SECRET"],
"scope": "claims.read",
})
r.raise_for_status()
body = r.json()
_token.update(value=body["access_token"], expires=time.time() + body["expires_in"])
return _token["value"]Consuming APIs: pagination and rate limits
Enterprise APIs return data in pages and limit how fast you may call them. Prefer cursor (or token) pagination, which stays correct when records change during the read, over page-number pagination, which can skip or repeat records. Respect rate limits: read Retry-After on 429 responses, back off, and keep concurrency low until you know the limits. A runaway integration that overloads a customer system is a fast way to lose access.
def fetch_all(client, path: str, page_size: int = 200):
cursor = None
while True:
params = {"limit": page_size, **({"cursor": cursor} if cursor else {})}
r = client.get(path, params=params,
headers={"Authorization": f"Bearer {access_token()}"})
if r.status_code == 429:
time.sleep(int(r.headers.get("Retry-After", "5")))
continue
r.raise_for_status()
body = r.json()
yield from body["items"]
cursor = body.get("next_cursor")
if not cursor:
breakWebhooks: receiving events safely
With webhooks, the customer's system calls you when something happens. Three rules keep them safe and correct. Verify every request's signature (usually an HMAC of the raw body with a shared secret) and reject anything unsigned or old. Respond quickly (within a few seconds) with 2xx and process asynchronously, because senders time out and retry. And make processing idempotent, because senders deliver at least once and duplicates are normal.
import hashlib
import hmac
import os
import time
SECRET = os.environ["WEBHOOK_SECRET"].encode()
def verify(raw_body: bytes, signature_hex: str, timestamp: str, max_age_s: int = 300) -> bool:
if abs(time.time() - int(timestamp)) > max_age_s:
return False # reject replays of old requests
expected = hmac.new(SECRET, timestamp.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, signature_hex) # constant-time comparisonEach provider documents its own header names and signing format; follow it exactly, and always sign over the raw bytes, not re-serialised JSON. Store the event ID of every processed event and skip ones you have seen.
Files and databases
Plenty of enterprise data still moves as files: nightly CSV or XML exports dropped on an SFTP server. Robust file integrations agree a naming convention, wait for a completion signal (a .done marker file or an atomic rename) so you never read a half-written file, verify a checksum or row count, process each file exactly once by recording processed file names, and move processed files to an archive folder rather than deleting them.
For databases, read from a replica or reporting view, never hammer the primary, and read incrementally using a watermark: the highest updated_at (or a monotonically increasing ID) you have processed. Overlap the window slightly to catch late commits, and dedupe on the primary key. Where the customer supports it, change data capture (CDC) streams inserts, updates and deletes from the database log and catches deletes that watermarks miss.
-- :last_watermark is the max(updated_at) from the previous successful run
SELECT claim_id, status, amount, updated_at
FROM claims_view
WHERE updated_at >= :last_watermark - INTERVAL '10 minutes'
ORDER BY updated_at, claim_id;
-- upsert by claim_id on the target, then store the new max(updated_at)Legacy SOAP services are still common in insurance, banking and government. Python's zeep library reads the WSDL and generates callable operations; treat the service like any other API with timeouts, retries and logging.
Patterns that keep integrations correct
- Idempotency: every write keyed so repeating it has no extra effect (upserts, idempotency keys, processed-event tables).
- At-least-once with dedupe beats chasing exactly-once delivery: accept duplicates and make them harmless.
- Quarantine / dead-letter queue: records or events that fail validation go somewhere visible with the reason, instead of blocking the pipeline or vanishing.
- Watermarks stored only after success, so a failed run re-reads rather than skips.
- Reconciliation: periodically compare counts or totals between source and target and alert on drift.
- Contract tests: a test that checks the shape of the partner's responses, so you notice when they change.
- Observability: per-run counts (read, written, quarantined), last success time and lag, with alerts.