Currently Available: Need a skilled Software Developer for your next project?
Categories
APIs

API Architecture Styles and Production Concepts Developers Should Know

When one piece of software asks another for data or an action, it uses an API. The architecture style you choose determines how clients send requests and how services return results. That choice shapes how easily developers can use your interface, how tightly your services depend on each other, and what your team has to handle when requests fail or traffic spikes.

Each style handles requests differently. With REST, clients send requests to resources. With RPC (remote procedure call), they call named operations. With GraphQL, they ask for specific fields in the response, and with event-driven APIs, they send messages for other services to process later. You can combine these styles in one product. A public REST API can serve a mobile app, gRPC can connect your internal services, and message queues can trigger background work. Your API style also stays separate from how you deploy your software. A single monolithic application or a set of microservices can use any of these styles.

Four ways APIs communicate

Before picking a style, look at what the caller needs to do, who will use the interface, and whether the caller must wait for an immediate answer. You can use more than one of these styles in the same system.

Style How the caller communicates Useful when Main cost to manage
REST over HTTP Sends requests to resources using HTTP methods Clients need broad compatibility and clear resource operations A client may need several requests to assemble a screen or workflow
RPC, including gRPC Calls a named operation defined by a service contract Services need explicit operations, generated clients, or streaming Clients and servers must stay compatible with the contract and protocol
GraphQL Requests selected fields from a typed schema Different clients need different response shapes The server must control query cost, authorization, and execution
Event-driven messaging Sends messages for consumers to process asynchronously Work can finish later, needs buffering, or must reach multiple consumers The team must handle duplicates, ordering, retries, and delayed results

REST over HTTP

REST APIs organize operations around resources, such as orders or accounts. Clients use HTTP methods to act on those resources, and servers return status codes and representations, usually in JSON. The HTTP standard gives each method a clear meaning: GET retrieves information, PUT replaces a resource representation, and POST runs processing defined by the target resource. The HTTP Semantics specification also marks which methods are safe, meaning the client does not ask the server to change state, and which are idempotent, meaning a client can repeat the request and produce the same intended effect as sending it once.

Idempotency matters when a client times out. Even if the response never arrives, the server might have finished the work. Because of that, clients should not automatically retry a non-idempotent request unless they can confirm that repeating it is safe. Match each HTTP method to what it actually does, return accurate status codes, and document the interface in a contract such as OpenAPI, which gives clients and servers a written specification of how to interact.

RPC and gRPC

RPC models an API as named operations, such as CreateOrder or GetAccount. gRPC is an RPC framework where you define services and methods, commonly in Protocol Buffer files, and generate client and server code from those files. As the gRPC introduction explains, it also supports patterns like streaming, where a client and server send data over an ongoing connection.

RPC works well when a caller thinks in terms of commands or service methods. Generated code saves your team from writing repetitive client logic and serialization code, though clients and servers still have to stay compatible with the shared contract and protocol. Many teams use gRPC for internal calls that benefit from typed interfaces or streaming. Still, do not assume gRPC will be faster for every workload. Test it with the payloads, runtimes, network conditions, and implementation you plan to run in production.

GraphQL

GraphQL lets a client pick the exact fields it wants from a schema, which describes the available data and its types. A product page can request an item's name, price, and inventory in one query, while another client asks for a different set of fields. GraphQL uses queries for reads, and servers can also offer mutations for writes and subscriptions for ongoing updates. The GraphQL query documentation covers how these operations work.

Because clients decide what goes into each response, server operators have to cap the amount of work a single query can trigger. Set limits on query complexity, execution time, pagination, and resource use. Check that the caller has permission to access every object and field it asks for so a client cannot pull sensitive data simply by adding a field to its query. OWASP's guidance on unrestricted resource consumption recommends controls like timeouts and caps on records per page.

Event-driven messaging

In an event-driven API, a producer sends messages for consumers, which are the services or programs that receive and process them. The producer does not have to hold a request open until the work finishes. A queue can absorb a sudden spike in traffic and hold those messages until consumers catch up. With a competing-consumers setup, one worker handles each work item. With publish-subscribe, multiple subscribers can receive the same event. Microsoft's competing consumers guidance explains how these patterns differ.

When an HTTP request kicks off work that will finish later, the server can respond with 202 Accepted. That tells the caller the server took the request and has not finished processing it yet. Your contract should spell out how the caller gets the final result, whether by polling a status resource or waiting for a callback or event. You can use AsyncAPI to document message-based interfaces, including how consumers deal with duplicate or failed messages.

Pick a style based on how callers interact

Start with what the caller needs to accomplish. Use HTTP and REST when consumers need broad client compatibility and operations centered on resources. Use RPC when the interface maps cleanly to commands or service methods. Choose GraphQL when different clients need very different data shapes and your server can enforce query limits. Choose messaging when the caller should hand off work, when a queue needs to buffer bursts, or when multiple subscribers need the same event.

Send a synchronous request when the caller needs an immediate answer, such as checking whether a payment request was accepted. Send a message to a queue when the work takes longer or can run independently. If you use a queue, the caller has to handle delayed results and possible redelivery. Your internal services do not all have to share one style. A single product can expose REST to external customers, run gRPC between internal services, and publish events for downstream work.

Keep your API style separate from your deployment shape. Microservices can talk through synchronous calls, messages, or both, and a monolith can expose REST or GraphQL. For more detail, see gRPC vs. REST and modern API design practices.

Build contracts that survive change

Treat your API as an agreement with its consumers about how they can use it. Avoid mirroring your database tables or internal code directly in the API. If you expose your storage layout too closely, a database change can break your clients. Document the API's public behavior and be clear about what compatibility guarantees clients can rely on.

Pick a contract format that fits the interface: OpenAPI for HTTP APIs, Protocol Buffers for gRPC, and AsyncAPI for messages. A schema helps people and tools understand the interface, though it does not guarantee that your implementation is secure or backward compatible. Before you change a field, method, or message, check which consumers depend on it. Then plan how you will roll out the change and retire the old version. No single versioning scheme or deprecation timeline works for every API.

Design retries around duplicate work

When a request times out, the caller only knows it did not receive a response in time. It cannot tell whether the server finished the operation. If the client retries a command that is not safe to repeat, the server might run the work twice.

Make operations safe to repeat whenever their behavior allows it. For commands that must never run twice, add a deduplication mechanism such as an idempotency key, and define how long the server remembers a repeated request. Set timeouts and retry caps, and only retry errors where another attempt makes sense. Aggressive retries can overload a service that is already struggling. You can pair a retry pattern with a circuit breaker, which temporarily stops sending calls to a failing dependency.

Messages can also show up more than once. A consumer might finish its work and crash before acknowledging the message, which prompts the broker to send it again. Write your consumers so they can handle repeated messages safely, define how they deal with out-of-order delivery, and route messages that keep failing to a dead-letter queue for inspection. A broker's delivery guarantee by itself does not ensure that a business effect happens only once.

Protect objects, fields, and resources

Authentication verifies who the caller is, and authorization controls what that caller can read or change. Check permissions for every specific object and action. Knowing an order ID should not give a user access to that order, and having permission to view an account should not automatically let a user edit every field on it.

Cap how much work any single request can trigger. Rate limits, payload-size caps, page-size limits, and execution timeouts help keep callers from exhausting your resources. OWASP's API security guidance separates authorization failures by objects, properties, and functions. Use it alongside threat modeling when you review your security, keeping in mind that it does not rank how often each risk happens.

Keep gateways focused and APIs observable

An API gateway gives clients a single entry point for shared tasks like routing, authentication, caching, and throttling. A backend-for-frontend (BFF) is a backend built for one specific client, such as a mobile app. A BFF can shape responses for that client, though your team has to run and maintain an extra service. Keep your gateway focused on concerns shared across clients, and leave domain decisions in the services that own them. Microsoft's gateway guidance warns that a gateway can turn into a bottleneck if you load it with business logic for individual clients.

To understand what your APIs are doing in production, collect logs, metrics, and traces. Logs record discrete events, metrics measure how services behave over time, and traces follow a request as it moves across services. OpenTelemetry's signal overview explains how these signals fit together. Track request latency, error rates, and dependency health. For message-based systems, also watch queue depth, message age, retries, and dead-letter volume. Attach trace context to your log records so engineers can follow a failure across service boundaries.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *