{}DSA Atlas

API Styles — REST, GraphQL, gRPC & Async APIs

When to choose REST, GraphQL, gRPC, plain RPC, webhooks or event-driven async APIs; GraphQL schemas, resolvers, N+1 and DataLoader, query cost limits and caching; gRPC/protobuf schema evolution; Backend-for-Frontend; and AsyncAPI/event contracts.

Intermediate5 interview questions

The landscape

StyleParadigmTransport / formatStrengthsWeaknessesTypical use
RESTresourcesHTTP + JSONsimple, cacheable, ubiquitousover/under-fetching, many round tripspublic APIs, CRUD
GraphQLtyped graph queriesHTTP POST + JSONexact data per screen, one round trip, schemacaching, cost control, complexitymulti-client frontends, aggregation
gRPCRPCHTTP/2 + Protobuffast, typed, streaming, codegenbrowsers need proxies, less human-readableinternal microservices, mobile
JSON-RPC / tRPCRPCHTTP + JSONsimple; tRPC gives end-to-end TS typesnot resource-oriented, weak cachinginternal/full-stack TS apps
WebhookscallbacksHTTP POSTpush to third partiesdelivery reliability, securityintegrations (payments, Git)
Event streamsasync messagesKafka/AMQP/MQTTdecoupling, fan-out, replayeventual consistency, opsinter-service events, analytics
SOAPRPC + XMLHTTP/other + XMLWS-* standardsverbose, legacyenterprise/banking legacy

GraphQL

Schema and query

GraphQL
type Query {
  post(id: ID!): Post
  posts(first: Int = 20, after: String): PostConnection!
}

type Post {
  id: ID!
  title: String!
  author: User!
  comments(first: Int = 10): [Comment!]!
}

type User { id: ID!, name: String! }
type Comment { id: ID!, body: String!, author: User! }

type Mutation {
  createPost(input: CreatePostInput!): Post!
}
GraphQL
# the client asks for exactly what the screen needs
query Feed {
  posts(first: 10) {
    edges { node { id title author { name } comments(first: 2) { body } } }
    pageInfo { endCursor hasNextPage }
  }
}

Resolvers and the N+1 problem

Naive resolvers SELECT * FROM posts LIMIT 50 SELECT * FROM users WHERE id=1 SELECT * FROM users WHERE id=2 … 50 more queries With DataLoader SELECT * FROM posts LIMIT 50 SELECT * FROM users WHERE id IN (…) 2 queries total, deduplicated DataLoader batches keys requested in the same tick and caches per request
Batch and cache per request to avoid query explosions.
TypeScript
import DataLoader from "dataloader";

// one loader instance per request (so caching never leaks between users)
const userLoader = new DataLoader(async (ids: readonly string[]) => {
  const rows = await db.query("SELECT * FROM users WHERE id = ANY($1)", [ids]);
  const byId = new Map(rows.map((u) => [u.id, u]));
  return ids.map((id) => byId.get(id) ?? null);        // same order as requested
});

const resolvers = {
  Post: { author: (post) => userLoader.load(post.authorId) },
};

Operating GraphQL safely

ConcernPractice
Abuse / expensive queriesdepth limits, cost analysis, pagination caps, timeouts
Cachingpersisted queries via GET + CDN; normalised client caches (Apollo, Relay)
Authorizationper-field/per-type checks in resolvers or a policy layer — never only at the gateway
Errorspartial data + errors array; HTTP 200 for field errors (monitor them!)
Federationcompose subgraphs owned by different teams (Apollo Federation, GraphQL Mesh)
Subscriptionsreal-time over WebSockets/SSE

gRPC and Protobuf

Protobuf
syntax = "proto3";
package payments.v1;

service PaymentService {
  rpc CreatePayment(CreatePaymentRequest) returns (Payment);
  rpc StreamPaymentEvents(StreamRequest) returns (stream PaymentEvent);
}

message CreatePaymentRequest {
  string idempotency_key = 1;
  int64 amount_minor = 2;
  string currency = 3;
  reserved 4;                 // field removed — never reuse number 4
  string customer_id = 5;
}

Schema evolution rules: never reuse field numbers, add fields rather than change them, treat enums as open, version the package for breaking changes, and run breaking-change checks in CI (buf breaking).

Choosing a style: decision guide

SituationChoose
Public API for third-party developersREST (+ OpenAPI), webhooks for events
Many client apps with different data needsGraphQL or a BFF per client
High-throughput internal calls, polyglot servicesgRPC
Streaming between servicesgRPC streams or a log (Kafka)
Fire-and-forget, fan-out, decoupled teamsevents on a broker
Simple full-stack TypeScript apptRPC / server actions
Browser real-timeSSE / WebSockets

Backend-for-Frontend

Web app iOS / Android Partners Web BFF Mobile BFF Public REST API users service (gRPC) orders service (gRPC) catalog service (gRPC)
Each client gets an API shaped for its screens; core services stay generic.

Event-driven / async APIs

Document event contracts like any other API: event name, version, schema (JSON Schema, Avro, Protobuf with a schema registry), producer, ordering and delivery guarantees. AsyncAPI is the OpenAPI equivalent for message-driven APIs. See Queues & streams.

Interview questions

0 / 5 marked confident

Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.