PAU OJ Online Judge
ProblemsLearnStudy plansContestsSubmissionsRank

Updates

Announcements and upcoming contests

Loading announcements…
Sign in for personal alertsBrowse contests
Log inSign up

PAU OJ

PrimeAsia University Online Judge

A real online judge for programming practice, university contests and coding assessments. Write code in your browser, get sandboxed verdicts, and track your progress.

Platform

  • Problems
  • Contests
  • Submissions
  • Ranking
  • Reviewers

Resources

  • User guide
  • Changelog
  • How judging works
  • System health
  • Create an account

© 2026 PrimeAsia University Online Judge. All rights reserved.

v0.9.0

  1. All tracks
  2. Master class
  3. REST, RPC & GraphQL

REST, RPC & GraphQL

REST, RPC ও GraphQL

Topic 21 of 41Story · visual · design practice

In this lesson

  • Story & concept
    • কেন দরকার
    • মূল ধারণা
    • কোডে দেখি
    • ধাপে ধাপে
    • সাধারণ ভুল
      • ল্যাব: এক screen-এর call গোনো
      • চিট শিট
      • প্রোডাকশন নোট
  • Visual story
  • Design practice
  • Checkpoint
  • Discussion
Back to track

0/0 solved

REST/gRPC/GraphQL, pagination, idempotency, versioning আর mobile payload।

In this lesson

  • Story & concept
  • Visual story
  • Design practice
  • Checkpoint
  • Discussion
01

Step 1: Story & concept

Start with the production incident, then the design decision that fixes it.

কেন দরকার

চলো-র mobile home screen-এ ১২টা API call হচ্ছিল: rider profile, upcoming ride, wallet, nearby drivers, promo, notifications… প্রতিটা call-এ ৩G-তে ৩০০ms latency, total ৩ সেকেন্ড। Websocket update-ও ছিল না। নুসরাত দেখল, একই screen-এর data চারটা endpoint-এ ছড়ানো; mobile-এ প্রতিটা round-trip দামি। তারপর সে একটা aggregate endpoint বানাল, কিন্তু response-এ ৪০টা field পাঠাল—যার ৮০% UI ব্যবহার করে না।

API design মানে শুধু URL নয়; client-এর দরকার, payload size, latency, versioning, error contract। REST, RPC (gRPC), GraphQL—তিনটারই জায়গা আছে; ধর্ম নয়, trade-off।

মূল ধারণা

REST। Resource + HTTP verb: GET /rides/{id}, POST /rides, PATCH. Cacheable GET, stateless, widely understood। কিন্তু multiple client view-এ over/under-fetching; chatty mobile।

RPC/gRPC। Procedure call, protobuf binary, HTTP/2; internal service-to-service-এ দ্রুত, typed, streaming। Public browser-এ gRPC-web/compat দরকার; human-debuggable নয়।

GraphQL। Client query-তে field বেছে নেয়; over-fetching কম, এক call-এ multiple resource। কিন্তু nested query cost, N+1, caching কঠিন, authorization per field; complexity budget দরকার।

Pagination। Offset (?page=2) সহজ, কিন্তু deep page ধীর, insert-এ duplicate। Cursor (?after=id) scalable, stable; UI infinite scroll-এ ভালো।

Idempotency। POST retry-তে duplicate; Idempotency-Key header + server store। PUT idempotent, PATCH নয়; payment-এ key বাধ্যতামূলক।

Versioning/error। URL /v1, breaking change-এ নতুন version; additive field safe। Error: stable code + human message + request_id; HTTP status semantics ঠিক।

চাহিদাRESTgRPCGraphQL
Public/browserভালোদুর্বলভালো
Mobile payloadমাঝারিভালোভালো
StreamingSSE/WSভালোsubscription
Cacheসহজকঠিনকঠিন
Internal RPCমাঝারিসেরাকম

কোডে দেখি

Cursor pagination আর idempotent POST:

GET /v1/rides?limit=20&after=ride_01J...
Idempotency-Key: 7f4c2a...

POST /v1/rides
{ "pickup": "...", "drop": "..." }
def list_rides(cursor, limit=20):
    rows = db.fetch(
        "SELECT id, created_at FROM rides WHERE (created_at, id) < ($1, $2) "
        "ORDER BY created_at DESC, id DESC LIMIT $3",
        (cursor.created_at, cursor.id, limit + 1),
    )
    return rows[:limit], rows[limit - 1].id if len(rows) > limit else None
query Home {
  me { id name wallet }
  upcomingRide { id status driver { name } }
}

GraphQL-এ client exact field চায়; server-এ depth limit, query cost, per-field auth লাগবে।

ধাপে ধাপে

১. Client/channel ঠিক করো। Public web/mobile REST/GraphQL; internal service gRPC; realtime SSE/WS।

২. Contract লিখো। Resource/Procedure, request/response schema, error code, pagination, idempotency.

৩. Mobile budget। Screen অনুযায়ী aggregate/BFF endpoint; response <100KB; compression; cache header.

৪. Version/backward compat। Additive field, /v1; deprecation timeline; client telemetry.

৫. Failure contract। 4xx vs 5xx, retryable, request_id, rate limit 429; docs/example।

সাধারণ ভুল

  • প্রতিটা screen-এ ১০–১২টা REST call। Mobile-এ round-trip দামি; BFF/aggregate endpoint ভাবো।
  • GraphQL-এ depth/cost limit না দেওয়া। একটা nested query DB মেরে দেবে।
  • Offset pagination deep page-এ। Cursor ব্যবহার করো; insert-এ duplicate এড়াবে।
  • POST retry-তে idempotency key না থাকা। Payment/booking-এ duplicate হবে।
  • Breaking field বদলে version না বাড়ানো। Additive field রাখো, deprecation timeline দাও।
  • Error-এ stack/DB detail leak। Stable code + request_id + safe message।

ল্যাব: এক screen-এর call গোনো

একটা mobile home screen-এর ৬টা data block লেখো। প্রতিটার জন্য REST call ধরলে কত round-trip, কত payload? GraphQL-এ এক query-তে কত? BFF/aggregate endpoint-এ কত? 3G latency 300ms ধরে total time মেলাও।

চিট শিট

প্রোডাকশন নোট

Response-এ internal field/DB column leak করো না; serializer/allowlist। GraphQL depth/cost limit না দিলে একটা query DB মেরে দেবে। Public API-তে version/deprecation policy, OpenAPI schema, rate limit—সব এক জায়গায় document করো।

02

Step 2: Visual story

See the mental model first — the animation and the steps below it say the same thing.

Concept visual

চুক্তি আগে, তারপর কোড

REST, RPC না GraphQL—যে চুক্তি মোবাইলের payload আর versioning সামলাতে পারে, সেটাই বাছো।

1GET /rides
2JSON
3ETag
4page 2
5mobile

GET /rides → JSON → ETag → page 2 → mobile

  1. 1resource আর verb ঠিক করোGET /rides, POST /rides
  2. 2paginate করোcursor দিলে page বদলায় না
  3. 3idempotency key দাওএকই POST দুইবার এলেও এক payment
  4. 4version ভাঙো না/v1 রেখে নতুন field যোগ করো
  5. 5mobile payload মাপোঅতিরিক্ত field মানে ডেটা খরচ
5টি ধাপে দেখা হচ্ছেগতি কমালে স্থির
03

Step 3: Design practice

Write a short design on paper or in a note, then compare it with the rubric. This is not a judge submission.

Design practice

Mobile home screen API

20 min

home screen-এ ৬টা data block, 3G latency 300ms, ১২টা REST call।

তোমার কাজ

  1. 1BFF/aggregate design করো।
  2. 2REST vs GraphQL vs gRPC বাছো।
  3. 3cursor pagination + idempotency contract লেখো।

ভালো উত্তরে কী থাকবে

  • round-trip/payload কমেছে
  • choice justified
  • pagination/idempotency আছে
04

Step 4: Checkpoint

One timed attempt. Solve every problem to earn the module badge.

Final checkpoint

Ready to prove this module?

45 minutes3 problemsScale Architect badge
Go to checkpoint
05

Step 5: Discussion

Ask questions, share an approach or leave a study tip for this lesson.

Was this lesson helpful?

Your reaction helps other learners judge these notes.

Sign in to react

Discussion

0 comments

Sign in to ask a question or share an approach.

Sign in to comment

No comments yet

Be the first to ask a question or leave a study tip.

Topic 21 of 41

PreviousFiles & Mediaফাইল ও মিডিয়াTopic 20 of 41
NextMessage Queuesপরে করো, হারিও নাTopic 22 of 41
Back to track: System Design MasterclassAll learning tracks
প্রশ্নউত্তর
Public API?REST/GraphQL
Internal?gRPC
Mobile?BFF/aggregate
Pagination?cursor
Retry?Idempotency-Key
Breaking?/v2 + deprecation