- Asp.Net Core
- 2
- September-20-2025
- by Ihsan Ullah
Q: How to keep auth stable?
A: Choose OAuth2 with refresh tokens. Store secrets in a vault. Request least-privilege scopes. Build a small token service that refreshes before expiry and exposes tokens to callers. Log vendor error
and error_description
. Rotate keys on a schedule.
Q: How to survive rate limits?
A: Read vendor docs for exact quotas. Respect Retry-After
. Add client-side throttling per API key. Batch or cache reads. Spread traffic across minutes rather than bursts. Create dashboards for 4xx/429 rates.
Q: How to handle timeouts/flaky networks?
A: Set short connect/read timeouts. Retry only idempotent operations. Use a circuit breaker so failing endpoints open quickly and recover gradually. Provide graceful fallbacks and user-visible status.
Q: How to avoid duplicate effects on retries?
A: For each “logical operation,” generate a unique operation ID. Send it with the request and store outcome against that ID. On retry, return the stored outcome.
Q: How to avoid breaking changes?
A: Pin the API version in every request. Subscribe to vendor change logs. Run nightly contract tests that hit the sandbox and verify required fields. Track deprecation headers and schedule upgrades.
Q: How to page reliably?
A: Prefer cursor/tokens over offsets. Loop until no next
token. De-duplicate by stable IDs. Persist the last token so jobs can resume after failure.
Q: How to secure webhooks?
A: Put webhooks behind an allowlist and a separate ingress endpoint. Verify vendor signature and timestamp. Enforce idempotency using the event ID. Accept, queue, then process to keep the endpoint fast.
Q: How to handle currency/time/locale?
A: Always send explicit currency codes and ISO-8601 timestamps with timezone. Convert to UTC internally. Render for users in their locale on output.
Q: How to cut payload and latency?
A: Use vendor fields-filtering and bulk endpoints. Compress over the wire. Parallelize reads with sane concurrency caps. Cache stable GETs with TTLs and cache keys that include all query params.
Q: How to prevent secret leaks?
A: Centralize logging with redaction. Never log headers or bodies from auth paths. Use short-lived credentials. Rotate and monitor access to the vault.
Q: How to meet legal/compliance needs?
A: Sign the DPA. Verify data residency and subprocessors. Classify data you store. Minimize retention. Provide deletion paths and audit trails.
Q: How to test without breaking prod?
A: Use the vendor sandbox. Seed deterministic fixtures. Record/replay happy and failure paths. Add contract tests that validate required fields and enums. Run chaos tests for timeouts and 5xx.
Implementation flow (fits ASP.NET MVC5 / EF6 / Hangfire)
-
Discovery
-
Read API docs: auth, quotas, pagination, webhooks, versioning.
-
List endpoints, payload shapes, and SLAs.
-
Decide sync vs async: direct calls in requests vs background jobs.
-
Design
-
One client per vendor with its own base URL, headers, and policies.
-
Token service owned by you.
-
Idempotency model: operation IDs + result store.
-
Caching strategy for GETs.
-
Webhook ingress: verify, enqueue, process.
-
Observability
-
Metrics: latency, success %, error by type, retries, breaker state, rate-limit hits.
-
Tracing: correlation IDs from user → API call → webhook.
-
Logs: structured with redaction.
-
Data model
-
Tables for: outbound requests, idempotency keys, pagination cursors, webhooks received, vendor objects cache, error catalog.
-
Use EF6 migrations to add these.
-
Job orchestration
-
Hangfire recurring jobs per endpoint for sync tasks.
-
Queues per vendor priority.
-
Dead-letter queue for poison events.
-
Error strategy
-
Map vendor errors to actions: retry, fix input, or alert.
-
Backoff with jitter.
-
Kill switch per endpoint if error rates spike.
-
Security
-
Secrets in a vault. Least privilege. IP allowlists where offered.
-
Webhook signature verification.
-
Access reviews and key rotation calendar.
-
Compliance
-
Document data flows.
-
Retention policy per data class.
-
Incident runbook and contact list for the vendor.
-
Rollout
-
Feature flag around the integration.
-
Canary with 1–5% traffic.
-
Budget caps for costed APIs.
-
On-call playbook with clear rollback.
-
Maintenance
-
Watch vendor status pages and change logs.
-
Renew credentials before expiry.
-
Quarterly disaster drills: token expiry, 429 storms, webhook outage.
Acceptance checklist
-
Auth refresh works without user impact.
-
Idempotent writes verified by replay test.
-
Pagination completes and resumes after crash.
-
Webhooks validated, queued, deduped, and ordered.
-
Rate-limit compliance proven under load.
-
PII redaction present in logs.
-
Dashboards and alerts in place.
-
Runbook links and on-call rotations set.