Almost every business system in Indonesia eventually has to talk to another: WhatsApp Business API for notifications, a payment gateway for transactions, a bank API for reconciliation, a marketplace for catalogue data, or a tax system for invoices. All of that is designed through API development and integration. The API integration layer sits between those systems, and the quality of that layer determines how far your system can grow without constant manual intervention. This guide covers the practices that matter most in a B2B API integration: authentication, versioning, idempotency, error handling, rate limiting, webhooks, observability, pagination, and documentation.

Why API Integrations Fail in Production

A new integration will look fine during testing, because testing happens under ideal conditions: fast network, a partner that is not busy, small payloads, and errors that never occur. Production is where every one of those assumptions gets tested.

  • Retries without an idempotency key, so a timed-out request that gets resent creates a duplicate transaction
  • Partner errors that are not classified, so every failure looks the same and the system retries indefinitely
  • Rate limits ignored because there is no queue and no backpressure, until the partner blocks your IP
  • Endpoints changed without versioning, so one small change breaks several integrations at once
  • No observability, so when something breaks nobody knows which request was wrong and why
  • Payloads too large without pagination, so the integration dies as data volume grows
The core principle

A good integration is not one that never fails, but one that fails in an expected way: isolated, logged, and recoverable without manual intervention.

Authentication: Choosing Between API Key, OAuth 2.0, and mTLS

The authentication method is often chosen too quickly, usually API key because it is fastest to implement. For a B2B system that will run for months, that choice determines how large the credential exposure risk becomes.

An API key suits internal service-to-service communication, and that is also part of the custom web application work we do, where there is no user to identify. OAuth 2.0 suits third parties that need access on behalf of a specific user, and it is the standard enterprise partners almost always ask for. mTLS offers the highest security level because every client proves its identity with a certificate, which makes sense for systems handling sensitive data or high-value transactions.

MethodStrengthsWeaknessesUse it when
API KeySimple, quick to implementNo user identity, easy to leakCommunication between internal services
OAuth 2.0User identity, expiring tokensMore complex, refresh token managementThird-party integrations
mTLSHighest security, proven client identityCertificate management overheadSensitive data and large transactions

The three most common authentication methods, each with its strengths and the use case it fits best.

A combination often seen in B2B systems is OAuth 2.0 for partner access into your system, and API keys or mTLS for communication between your own internal services. Whichever you pick, credentials must never live in code: store them in a secret manager or environment variables, rotate them regularly, and make sure they never reach a log file.

Versioning: API Contracts That Do Not Break Consumers

Once your API is used by a partner or another team, every field change becomes a consequential decision. Solid versioning protects you from every unintended change. Backward compatibility is the safest rule: adding a field is always safe, removing a field or changing its type always breaks something, and changing the meaning of a field has to be announced explicitly.

  • Version in the URL path, such as /v1/orders, is the most explicit and easiest to debug
  • A version header for small changes, such as Accept-Version, keeps the URL untouched
  • New fields stay optional during the transition period so older consumers are not affected
  • A deprecated field is marked first and removed only after every consumer has migrated
  • Every breaking change gets a new version rather than being patched in place

Idempotency: Preventing Duplicate Transactions

This is the most common cause of integration problems in production. A client that times out does not know whether its request arrived. A well-behaved client then resends, and a server that does not distinguish the two records the transaction twice. An idempotency key solves this. The client generates a unique key per business operation, sends it with the request, and the server stores the first result for that key. A repeat request carrying the same key returns the same result with no new side effects.

  1. 1Generate the idempotency key uniquely per business operation, not per request
  2. 2Send it as a header rather than in the body, so the server can act on it before parsing the payload
  3. 3Store the key and its response in the database with a long enough retention window, typically 24 hours
  4. 4Return the identical response when the same key arrives again
  5. 5Reject the same key with a different payload, since that is almost always a client-side bug

Error Handling and Controlled Retries

Not every error is worth retrying. The HTTP status code the server returns is the first source of truth, and reading it correctly determines whether retrying helps or makes things worse. A 4xx response usually means the request itself is wrong, so resending only burns quota. A 429 or 5xx response is usually transient, which is exactly where retrying helps. Most importantly, read the Retry-After header the server sends, because that is the most accurate signal available.

Use exponential backoff with jitter. Pure backoff makes every client that failed together retry together, which adds load at exactly the moment the server is recovering. Jitter spreads each request's delay randomly so the retries do not align.

The retry flow: from the first request, through the backoff wait, to the dead letter queue for cases that never succeed.

  1. 1Classify errors: transient and retryable, permanent and not retryable, and business rejections that go back to the user
  2. 2Cap the number of attempts, typically three, so the queue does not pile up
  3. 3Use exponential backoff with jitter rather than a fixed interval
  4. 4Honour a Retry-After header when it is present, because it is an explicit instruction from the server
  5. 5Send requests that exceeded the limit to a dead letter queue for manual or automatic handling
  6. 6Use a circuit breaker so the system stops calling a partner that is down

Rate Limiting and Backpressure

Every public API has a rate limit, and partners usually publish it alongside the documentation. Exceeding the limit usually ends in an HTTP 429, but if you keep pushing, the partner can block your IP temporarily, which is far more damaging than waiting. Use a client-side rate limiter that respects the partner's limit, and a queue with a bounded length. When the queue is full, reject new requests quickly and clearly rather than accepting everything and letting it all run slowly while timeouts accumulate.

Webhook Design That Survives Reality

Webhooks are how partners notify your system, and in many internal company systems they end up being the most sensitive component, and they are often the most fragile point in an integration. Two things are mandatory: signature verification on every payload, and idempotent processing, because a webhook can be delivered more than once.

  • Verify the signature with HMAC and compare it in constant time to prevent timing attacks
  • Return a 2xx response quickly, then process asynchronously so the partner does not time out
  • Store the event ID so duplicate events can be ignored
  • Keep a polling fallback, because some webhooks go missing without a trace
  • Retry failed deliveries with exponential backoff and jitter, and alert the team when failures persist

Observability: Keeping Integrations Healthy

An integration that fails silently is the worst scenario, because you only find out from customer complaints. Every integration request should carry a correlation ID that appears both in your logs and the partner's, so a single incident can be traced end to end. Measure latency, success rate, and retry count per endpoint, then alert when the success rate drops.

  • Log requests and responses with sensitive fields redacted, and never log credentials
  • Send metrics: p50 and p95 latency, success rate, retry counts, and queue depth
  • Propagate a correlation ID to the partner through a header
  • Set up symptom-based alerts rather than cause-based ones, so they do not become noise
  • Keep raw payloads for a limited time for debugging, under a clear retention policy

Pagination and Payload Limits

An endpoint that returns a whole collection works with small data and breaks with large data. Use cursor-based pagination for data that changes frequently, because offset-based pagination can skip or repeat rows as new data arrives. Reserve offset pagination for the cases where you genuinely need to jump to a page number.

Documentation and SDKs

Good API documentation is part of the integration, not an extra. Every endpoint needs documented parameters, request and response examples, a list of error codes, and the rate limit behaviour. For B2B, publish an OpenAPI specification as the source of truth, then generate the documentation and the SDKs from that specification, so the documentation and the implementation can never drift apart.

Runnable request and response examples help integrators more than anything else. If your integration needs other teams, ship sample payloads that look like real data, together with the error examples that actually occur.

API Integration Checklist

  • The authentication method matches the use case, and credentials live in a secret manager
  • API versioning is decided from the start, including the policy for breaking changes
  • An idempotency key is used for every operation that writes data
  • Errors are classified, retries are capped, and backoff uses jitter
  • Rate limits are respected and the queue has a bounded length
  • Webhooks are signature-verified, processed idempotently, and backed by polling
  • Correlation IDs, metrics, and alerts are in place
  • Pagination is used on every endpoint that returns a collection
  • Documentation and sample payloads are available to integrators
  • Tests cover failure conditions, not only the happy path

When to Build and When to Buy the Integration

Not every integration is worth building from scratch. If a partner ships an SDK or an official library, use it, because that cuts work and reduces the surface area for bugs. Build it yourself when you need control over behaviour, data format, and recovery, or when no product fits.

Build every integration with a clear failure boundary. If you are designing a system that has to talk to several partners at once, API development and integration is the area that most often determines how quickly the system gets finished. Our custom system cost guide helps put the cost of integration into the context of the whole project, and a worked example is our face recognition attendance system, where several devices feed one data flow.

The first consultation carries no fee and commits you to nothing.

The first consultation carries no fee and commits you to nothing. We help map which integration is most urgent and which can wait.

Consult via WhatsApp

Frequently Asked Questions

What is a sensible timeout for a partner API request?+
Generally 10 to 30 seconds for a synchronous request, with a total timeout shorter than the calling client's timeout so you can return a clear error in time. For heavy work, use an asynchronous pattern with polling or webhooks instead of holding a connection open.
How should we handle rate limits from a partner?+
Read the 429 response and its Retry-After header, then use exponential backoff with jitter. Run a client-side rate limiter so your requests never exceed the partner limit, and keep a bounded queue so the system rejects clearly when saturated instead of accumulating timeouts.
When should we use webhooks and when polling?+
Webhooks are faster and cheaper, but delivery is not guaranteed and some get lost. Polling is simpler and easier to control, but it loads the partner's servers. For data that has to arrive promptly, use webhooks with a polling fallback.
Is an idempotency key required on every endpoint?+
Required on every endpoint that creates or modifies data, because that is where a repeat causes a duplicate side effect. Read-only endpoints do not need one. The key must be generated per business operation, not per request attempt.
How do we decide which API versioning approach to use?+
Versioning in the URL path is the most explicit and the easiest to debug, which makes it the right choice for an API with many partners. What matters most is consistency: adding fields is safe, but removing a field or changing its type requires a new version.