Mercado Tech Brasil

Plan API integration in solutions architecture: learn how

Published on · Solutions Architecture · by William Garcia

Network cables plugged into an equipment panel
Photo: Sakin Shrestha · WordPress Photo Directory (CC0, public domain)

This is article 4 of 10 in the Mercado Tech Brasil series on solutions architecture. After defining how the solution is organized on the inside, it is time to look outward: API integration, which lets different systems exchange information without relying on spreadsheets, copied screens or files sent by email.

Why API integration became the standard

An API is a contract: it states what a system offers, the format in which it accepts requests and what it returns. When the CRM needs to send a closed order to the ERP, the API defines the required fields, the validations and the possible responses. That contract lets each side evolve internally without breaking the other, as long as the agreement is respected.

The most common style today is REST over HTTP. In it, each resource, such as orders or customers, has an address, and the verbs express intent: GET reads, POST creates, PUT or PATCH update and DELETE removes. Status codes say what happened: the 200 family means success, the 400 family points to an error by the caller and the 500 family, a failure by the responder. Another important trait is being stateless: each call carries everything the server needs to handle it, which makes scaling easier.

API integration best practices in solutions architecture

Contract first

Design and review the contract before implementing it, using a specification such as OpenAPI. That way, the CRM and ERP teams work in parallel, generate documentation automatically and test against mocks before the other side is ready.

Changes that don't break consumers

Adding an optional field is usually safe. Renaming, removing or changing the type of a field breaks whoever already uses the API. For changes like these, publish a new version, keep the previous one for an agreed period and notify consumers in advance. The version can go in the URL path or in a header; what matters most is choosing one convention and always following it.

Idempotency and retries

Networks fail. If the ERP takes too long to respond, the CRM may resend the request and create two identical orders. An idempotency key, sent by the client with each operation, lets the server recognize the repetition and return the same result without duplicating anything. Combine this with timeouts and retries with increasing intervals.

Limits and protection

Set call limits per client so that one faulty integrator cannot take the service down for everyone. Require strong authentication, such as OAuth 2.0 with minimal permissions, always use HTTPS and log who called what and when.

When solutions architecture calls for another path

An API call waits for the answer right away. That is great for lookups, such as checking stock levels before confirming a sale. For long-running tasks or tasks that can wait, such as issuing documents in batches, forcing everything to be synchronous creates waiting lines and cascading failures. That is the topic of the next article.

In practice

In integration projects between CRM, ERP and customer service platforms, most of the problems I run into are not technical: they come from a poorly agreed contract. That is why I start with a specification reviewed by both ends, automated contract tests and a dashboard showing errors and response time per integration. Automation is only reliable when the conversation between systems is too.

Read also: Use messaging and events in solutions architecture: see when it fits

Translated from the original in Portuguese. Read the original.