REST, GraphQL, and gRPC
A shop app shows an order and the name of its customer. The app and the server must agree on how to ask for this data. REST, GraphQL, and gRPC are three common answers.
8 min read8 মিনিটে পড়া যায় · 8 sections8টি সেকশন · 8 sources8টি সোর্স · updated Nov 2026আপডেট: Nov 2026
One screen, three API stylesএকটা স্ক্রিন, তিন রকম API স্টাইল
Load an exam, its teacher and a score through REST, GraphQL and gRPC, then compare the calls and the fields that come back.REST, GraphQL ও gRPC দিয়ে একটা পরীক্ষা, তার শিক্ষক ও একটা স্কোর আনুন, তারপর কল আর ফেরত আসা ফিল্ড মিলিয়ে দেখুন।
You’ll learnআপনি শিখবেন
- Why REST can need three callsREST-এ কেন তিনটা কল লাগতে পারে
- How one GraphQL query saves callsএকটা GraphQL কোয়েরি কীভাবে কল বাঁচায়
- What a gRPC call through a stub isস্টাবের মাধ্যমে gRPC কল কী
- How the three report errorsতিনটি এরর কীভাবে জানায়
In plain words
An API is the way one program asks another for data or work. These names are not three versions of one thing. REST is a style of design. GraphQL is a query language. gRPC lets a program call a method on a remote server.
REST is an architectural style: a set of constraints chosen for the properties they give a system Source 1সোর্স 1. Fielding starts from a style with no constraints and adds client-server, stateless communication, caching, a uniform interface, and a layered system Source 1সোর্স 1. Code-on-demand is an optional extra Source 1সোর্স 1. The uniform interface is the feature that sets REST apart from other network styles Source 1সোর্স 1. It has four constraints Source 1সোর্স 1:
- Identification of resources.
- Manipulation of resources through representations.
- Self-descriptive messages.
- Hypermedia as the engine of application state.
REST does not limit communication to one protocol Source 1সোর্স 1. So "REST" does not mean "JSON over HTTP". A server can send JSON over HTTP and still not follow these constraints.
GraphQL is a query language for an API, plus a server-side runtime that runs queries against a type system that you define Source 2সোর্স 2. It is not tied to one database Source 2সোর্স 2. The client writes a query in the shape of the data it wants Source 2সোর্স 2.
gRPC lets a client call a method on a server on another machine as if the method were a local object Source 7সোর্স 7. By default it uses Protocol Buffers to describe and serialize the data Source 7সোর্স 7.
সহজ English
An API is the way one program asks another program for data or work. REST, GraphQL, and gRPC are not three versions of one thing. REST is a style of design. GraphQL is a query language. gRPC lets a program call a method on a remote server.
REST is an architectural style. It is a set of constraints. People chose the constraints for the properties that they give a system. Source 1সোর্স 1 Fielding starts from a style with no constraints. He adds client-server, stateless communication, caching, a uniform interface, and a layered system. Source 1সোর্স 1 Code-on-demand is an optional extra. Source 1সোর্স 1 The uniform interface sets REST apart from other network styles. Source 1সোর্স 1 It has four constraints: Source 1সোর্স 1
- Identification of resources.
- Manipulation of resources through representations.
- Self-descriptive messages.
- Hypermedia as the engine of application state.
REST does not limit communication to one protocol. Source 1সোর্স 1 So "REST" does not mean "JSON over HTTP". A server can send JSON over HTTP and still not follow these constraints.
GraphQL is a query language for an API. It also has a server-side runtime. The runtime runs queries against a type system that you define. Source 2সোর্স 2 GraphQL is not tied to one database. Source 2সোর্স 2 The client writes a query in the shape of the data it wants. Source 2সোর্স 2
gRPC lets a client call a method on a server on another machine, as if the method were a local object. Source 7সোর্স 7 By default it uses Protocol Buffers to describe and serialize the data. Source 7সোর্স 7
বাংলা ব্যাখ্যা
API হলো একটি প্রোগ্রামের অন্য প্রোগ্রামের কাছে ডেটা বা কাজ চাওয়ার উপায়। REST, GraphQL ও gRPC একই জিনিসের তিনটি ভার্সন নয়। REST হলো একটি ডিজাইন স্টাইল। GraphQL হলো একটি কোয়েরি ল্যাঙ্গুয়েজ (query language)। gRPC একটি প্রোগ্রামকে রিমোট সার্ভারের একটি মেথড কল করতে দেয়।
REST একটি আর্কিটেকচারাল স্টাইল (architectural style)। এটি কিছু কনস্ট্রেইন্টের (constraint) সমষ্টি। কনস্ট্রেইন্টগুলো বাছা হয়েছে সেগুলো সিস্টেমকে যে বৈশিষ্ট্য দেয়, তার জন্য। Source 1সোর্স 1 Fielding শুরু করেন কনস্ট্রেইন্ট ছাড়া একটি স্টাইল থেকে। তিনি যোগ করেন ক্লায়েন্ট-সার্ভার, স্টেটলেস কমিউনিকেশন, ক্যাশিং, ইউনিফর্ম ইন্টারফেস এবং লেয়ার্ড সিস্টেম। Source 1সোর্স 1 কোড-অন-ডিমান্ড একটি ঐচ্ছিক বাড়তি অংশ। Source 1সোর্স 1 ইউনিফর্ম ইন্টারফেস (uniform interface) REST-কে অন্য নেটওয়ার্ক স্টাইল থেকে আলাদা করে। Source 1সোর্স 1 এর চারটি কনস্ট্রেইন্ট আছে: Source 1সোর্স 1
- রিসোর্সের শনাক্তকরণ।
- রিপ্রেজেন্টেশনের মাধ্যমে রিসোর্স পরিবর্তন।
- নিজেই নিজেকে বর্ণনা করে এমন মেসেজ।
- অ্যাপ্লিকেশনের অবস্থার ইঞ্জিন হিসেবে হাইপারমিডিয়া।
REST যোগাযোগকে একটি প্রোটোকলে সীমাবদ্ধ করে না। Source 1সোর্স 1 তাই "REST" মানে "JSON over HTTP" নয়। একটি সার্ভার HTTP-র ওপর JSON পাঠিয়েও এই কনস্ট্রেইন্টগুলো না মানতে পারে।
GraphQL একটি API-র কোয়েরি ল্যাঙ্গুয়েজ। এর একটি সার্ভার-সাইড রানটাইমও আছে। রানটাইম আপনার সংজ্ঞায়িত টাইপ সিস্টেমের সাথে মিলিয়ে কোয়েরি চালায়। Source 2সোর্স 2 GraphQL কোনো একটি ডেটাবেসের সাথে বাঁধা নয়। Source 2সোর্স 2 ক্লায়েন্ট যে ডেটা চায়, তার আকারে একটি কোয়েরি লেখে। Source 2সোর্স 2
gRPC একটি ক্লায়েন্টকে অন্য মেশিনের সার্ভারের একটি মেথড কল করতে দেয়, যেন মেথডটি একটি লোকাল অবজেক্ট। Source 7সোর্স 7 ডিফল্টভাবে এটি ডেটা বর্ণনা ও সিরিয়ালাইজ করতে Protocol Buffers ব্যবহার করে। Source 7সোর্স 7
When you need it
This advice is the tutorial's own. You meet these styles whenever two programs talk over a network, for example a mobile app and its server. A tester must know which style an API uses, because it decides what a request, a contract, and an error look like.
সহজ English
This advice is the tutorial's own. You meet these styles whenever two programs talk over a network. For example, a mobile app talks to its server. A tester must know which style an API uses. The style decides what a request, a contract, and an error look like.
বাংলা ব্যাখ্যা
এই পরামর্শ টিউটোরিয়ালের নিজের। দুটি প্রোগ্রাম নেটওয়ার্কের ওপর কথা বললেই আপনি এই স্টাইলগুলোর দেখা পান। যেমন একটি মোবাইল অ্যাপ তার সার্ভারের সাথে কথা বলে। টেস্টারকে জানতে হবে একটি API কোন স্টাইল ব্যবহার করে। স্টাইল ঠিক করে একটি রিকুয়েস্ট, একটি কন্ট্রাক্ট (contract) এবং একটি এরর দেখতে কেমন হবে।
How it works
REST. The key idea is the resource: any information that can be named Source 1সোর্স 1. A resource is a mapping to a set of values, not the value at one moment Source 1সোর্স 1. Components send a representation: bytes plus metadata that describes them Source 1সোর্স 1. Its format is its media type Source 1সোর্স 1.
Each request must carry all the information needed to understand it, with no stored context on the server Source 1সোর্স 1. This helps visibility, reliability, and scalability, but repeats data in each request Source 1সোর্স 1. A response is labeled cacheable or not, and a cacheable one may be reused Source 1সোর্স 1. A response to a retrieval request is cacheable unless the message says otherwise Source 1সোর্স 1.
GraphQL. A service defines types and fields, and a function for each field Source 2সোর্স 2. These capabilities form the schema Source 4সোর্স 4. There are three operation types: query, mutation, and subscription Source 3সোর্স 3. A query starts at a root type and selects fields down to the leaf values, and the result mirrors the shape of the query Source 3সোর্স 3. The server checks the query against the schema, then runs the functions Source 2সোর্স 2. One query can follow links between related objects, saving round trips that a classic REST design may need Source 3সোর্স 3.
The specification does not require a protocol, but HTTP is the most common choice Source 5সোর্স 5. A server usually has one endpoint, often /graphql, and entities are not identified by URLs Source 5সোর্স 5. The server must handle POST for queries and mutations, and it may accept GET for queries Source 5সোর্স 5. The result is in a top-level data key, and errors are in a top-level errors key Source 3সোর্স 3.
gRPC. You define a service, with its methods, parameters, and return types, in a .proto file Source 7সোর্স 7. The compiler protoc generates code from it, and the client calls the methods on a stub Source 7সোর্স 7Source 8সোর্স 8. gRPC has four kinds of method Source 8সোর্স 8:
- Unary: one request, one response.
- Server streaming: one request, a stream of responses.
- Client streaming: a stream of requests, one response.
- Bidirectional streaming: both sides send streams.
A client can set a deadline. A call that takes longer ends with DEADLINE_EXCEEDED Source 8সোর্স 8. Each call ends with a status code and an optional message Source 8সোর্স 8.
সহজ English
REST. The key idea is the resource. A resource is any information that can be named. Source 1সোর্স 1 A resource is a mapping to a set of values. It is not the value at one moment. Source 1সোর্স 1 Components send a representation. A representation is bytes plus metadata that describes them. Source 1সোর্স 1 Its format is its media type. Source 1সোর্স 1
Each request must carry all the information needed to understand it. The server keeps no stored context. Source 1সোর্স 1 This helps visibility, reliability, and scalability. But it repeats data in each request. Source 1সোর্স 1 A response is labeled cacheable or not. A cacheable response may be reused. Source 1সোর্স 1 A response to a retrieval request is cacheable unless the message says otherwise. Source 1সোর্স 1
GraphQL. A service defines types and fields, and a function for each field. Source 2সোর্স 2 These capabilities form the schema. Source 4সোর্স 4 There are three operation types: query, mutation, and subscription. Source 3সোর্স 3 A query starts at a root type. It selects fields down to the leaf values. The result has the same shape as the query. Source 3সোর্স 3 The server checks the query against the schema, then runs the functions. Source 2সোর্স 2 One query can follow links between related objects. This saves round trips that a classic REST design may need. Source 3সোর্স 3
The specification does not require a protocol, but HTTP is the most common choice. Source 5সোর্স 5 A server usually has one endpoint, often /graphql. Entities are not identified by URLs. Source 5সোর্স 5 The server must handle POST for queries and mutations. It may accept GET for queries. Source 5সোর্স 5 The result is in a top-level data key. Errors are in a top-level errors key. Source 3সোর্স 3
gRPC. You define a service in a .proto file. You give its methods, parameters, and return types. Source 7সোর্স 7 The compiler protoc makes code from it. The client calls the methods on a stub. Source 7সোর্স 7Source 8সোর্স 8 gRPC has four kinds of method: Source 8সোর্স 8
- Unary: one request, one response.
- Server streaming: one request, a stream of responses.
- Client streaming: a stream of requests, one response.
- Bidirectional streaming: both sides send streams.
A client can set a deadline. A call that takes longer ends with DEADLINE_EXCEEDED. Source 8সোর্স 8 Each call ends with a status code and an optional message. Source 8সোর্স 8
বাংলা ব্যাখ্যা
REST। মূল ধারণা হলো রিসোর্স (resource)। রিসোর্স হলো যেকোনো তথ্য, যার নাম দেওয়া যায়। Source 1সোর্স 1 রিসোর্স হলো একসেট ভ্যালুর একটি ম্যাপিং। এটি কোনো এক মুহূর্তের ভ্যালু নয়। Source 1সোর্স 1 কম্পোনেন্ট একটি রিপ্রেজেন্টেশন (representation) পাঠায়। রিপ্রেজেন্টেশন হলো বাইট এবং সেগুলোকে বর্ণনাকারী মেটাডেটা। Source 1সোর্স 1 এর ফরম্যাট হলো এর মিডিয়া টাইপ (media type)। Source 1সোর্স 1
প্রতিটি রিকুয়েস্টে তা বোঝার জন্য প্রয়োজনীয় সব তথ্য থাকতে হয়। সার্ভার কোনো কনটেক্সট জমা রাখে না। Source 1সোর্স 1 এতে দৃশ্যমানতা, নির্ভরযোগ্যতা ও স্কেলেবিলিটির সুবিধা হয়। কিন্তু প্রতিটি রিকুয়েস্টে ডেটার পুনরাবৃত্তি হয়। Source 1সোর্স 1 একটি রেসপন্স ক্যাশযোগ্য (cacheable) বা ক্যাশযোগ্য নয় হিসেবে চিহ্নিত থাকে। ক্যাশযোগ্য রেসপন্স আবার ব্যবহার করা যেতে পারে। Source 1সোর্স 1 মেসেজ অন্যভাবে না বললে রিট্রিভাল রিকুয়েস্টের রেসপন্স ক্যাশযোগ্য। Source 1সোর্স 1
GraphQL। একটি সার্ভিস টাইপ ও ফিল্ড সংজ্ঞায়িত করে, এবং প্রতিটি ফিল্ডের জন্য একটি ফাংশন। Source 2সোর্স 2 এই সক্ষমতাগুলো মিলে স্কিমা (schema) তৈরি হয়। Source 4সোর্স 4 তিন ধরনের অপারেশন আছে: কোয়েরি, মিউটেশন ও সাবস্ক্রিপশন। Source 3সোর্স 3 একটি কোয়েরি একটি রুট টাইপ থেকে শুরু হয়। এটি লিফ ভ্যালু পর্যন্ত ফিল্ড বাছে। ফলাফলের আকার কোয়েরির আকারের মতোই হয়। Source 3সোর্স 3 সার্ভার স্কিমার সাথে মিলিয়ে কোয়েরি যাচাই করে, তারপর ফাংশন চালায়। Source 2সোর্স 2 একটি কোয়েরি সম্পর্কিত অবজেক্টের মধ্যে লিংক অনুসরণ করতে পারে। এতে সেই রাউন্ড ট্রিপ বাঁচে, যা একটি ক্লাসিক REST ডিজাইনে লাগতে পারে। Source 3সোর্স 3
স্পেসিফিকেশন কোনো প্রোটোকল বাধ্যতামূলক করে না, কিন্তু HTTP সবচেয়ে প্রচলিত পছন্দ। Source 5সোর্স 5 একটি সার্ভারে সাধারণত একটি এন্ডপয়েন্ট থাকে, প্রায়ই /graphql। এন্টিটি URL দিয়ে চেনা যায় না। Source 5সোর্স 5 কোয়েরি ও মিউটেশনের জন্য সার্ভারকে POST হ্যান্ডেল করতে হয়। কোয়েরির জন্য সে GET নিতে পারে। Source 5সোর্স 5 ফলাফল টপ-লেভেল data কী-তে থাকে। এরর থাকে টপ-লেভেল errors কী-তে। Source 3সোর্স 3
gRPC। আপনি একটি .proto ফাইলে একটি সার্ভিস সংজ্ঞায়িত করেন। এতে এর মেথড, প্যারামিটার ও রিটার্ন টাইপ দেন। Source 7সোর্স 7 কম্পাইলার protoc তা থেকে কোড তৈরি করে। ক্লায়েন্ট একটি স্টাবের (stub) ওপর মেথড কল করে। Source 7সোর্স 7Source 8সোর্স 8 gRPC-তে চার ধরনের মেথড আছে: Source 8সোর্স 8
- ইউনারি (Unary): একটি রিকুয়েস্ট, একটি রেসপন্স।
- সার্ভার স্ট্রিমিং (Server streaming): একটি রিকুয়েস্ট, রেসপন্সের একটি স্ট্রিম।
- ক্লায়েন্ট স্ট্রিমিং (Client streaming): রিকুয়েস্টের একটি স্ট্রিম, একটি রেসপন্স।
- বাইডিরেকশনাল স্ট্রিমিং (Bidirectional streaming): দুই পক্ষই স্ট্রিম পাঠায়।
একটি ক্লায়েন্ট ডেডলাইন (deadline) ঠিক করতে পারে। এর চেয়ে বেশি সময় লাগলে কল DEADLINE_EXCEEDED দিয়ে শেষ হয়। Source 8সোর্স 8 প্রতিটি কল একটি স্ট্যাটাস কোড এবং একটি ঐচ্ছিক মেসেজ দিয়ে শেষ হয়। Source 8সোর্স 8
Trade-offs
Each cell has a cite, or starts with "Tutorial's view", which means it is the tutorial's own judgment.
| REST | GraphQL | gRPC | |
|---|---|---|---|
| What it is | An architectural style with constraints Source 1সোর্স 1 | A query language and a server-side runtime Source 2সোর্স 2 | A way to call a method on a remote server as if it were local Source 7সোর্স 7 |
| Where the contract lives | Tutorial's view: there is no one schema file. The agreement is the uniform interface, with its resources, representations, and media types | In the schema of types and fields Source 4সোর্স 4 | In a service definition, by default a .proto file Source 8সোর্স 8 |
| Data on the wire | A representation in some media type Source 1সোর্স 1 | Clients and servers should support JSON Source 5সোর্স 5 | Protocol Buffers by default, other formats possible Source 7সোর্স 7 |
| Related data | Data moves in a standard form, not one fitted to each application, which can cost efficiency Source 1সোর্স 1 | One query can fetch related data in one request Source 3সোর্স 3 | Tutorial's view: a method returns what its message type defines, so related data is a design choice of the service |
| Caching | A cache constraint, and retrieval responses are cacheable by default Source 1সোর্স 1 | No URL-like unique id, so the API should expose ids for client caching Source 6সোর্স 6. GET for queries may help HTTP and CDN caching, but long queries can pass URL limits Source 5সোর্স 5 | Tutorial's view: the gRPC pages used here do not describe response caching, so check the team's design |
| Streaming and push | Tutorial's view: outside this page. The next page covers long polling, WebSockets, and SSE | Subscriptions are one operation type Source 3সোর্স 3 | Server, client, and bidirectional streaming Source 8সোর্স 8 |
| Errors | Tutorial's view: depends on the protocol in use, often HTTP status codes | A response can hold both data and errors, and the status can still be 2xx Source 5সোর্স 5 | A status code and an optional message Source 8সোর্স 8 |
| Best fit | Tutorial's view: resource-style APIs where caching and many different clients matter | Tutorial's view: clients that need different shapes of the same data | Tutorial's view: calls between services, and calls that stream |
REST costs. The REST interface has costs. Fielding writes that it lowers efficiency, and that it is not optimal for kinds of interaction other than large-grain hypermedia transfer Source 1সোর্স 1. A cache can also lower reliability when its old data differs a lot from the server's data Source 1সোর্স 1.
সহজ English
Each point has a cite, or starts with "Tutorial's view". "Tutorial's view" means it is the tutorial's own judgment.
What it is
- REST: an architectural style with constraints. Source 1সোর্স 1
- GraphQL: a query language and a server-side runtime. Source 2সোর্স 2
- gRPC: a way to call a method on a remote server as if it were local. Source 7সোর্স 7
Where the contract lives
- REST: Tutorial's view: there is no one schema file. The agreement is the uniform interface, with its resources, representations, and media types.
- GraphQL: in the schema of types and fields. Source 4সোর্স 4
- gRPC: in a service definition, by default a
.protofile. Source 8সোর্স 8
Data on the wire
- REST: a representation in some media type. Source 1সোর্স 1
- GraphQL: clients and servers should support JSON. Source 5সোর্স 5
- gRPC: Protocol Buffers by default. Other formats are possible. Source 7সোর্স 7
Related data
- REST: data moves in a standard form, not one fitted to each application. This can cost efficiency. Source 1সোর্স 1
- GraphQL: one query can fetch related data in one request. Source 3সোর্স 3
- gRPC: Tutorial's view: a method returns what its message type defines. So related data is a design choice of the service.
Caching
- REST: a cache constraint. Retrieval responses are cacheable by default. Source 1সোর্স 1
- GraphQL: there is no URL-like unique id. So the API should expose ids for client caching. Source 6সোর্স 6 GET for queries may help HTTP and CDN caching. But long queries can pass URL limits. Source 5সোর্স 5
- gRPC: Tutorial's view: the gRPC pages used here do not describe response caching. So check the team's design.
Streaming and push
- REST: Tutorial's view: outside this page. The next page covers long polling, WebSockets, and SSE.
- GraphQL: subscriptions are one operation type. Source 3সোর্স 3
- gRPC: server, client, and bidirectional streaming. Source 8সোর্স 8
Errors
- REST: Tutorial's view: it depends on the protocol in use, often HTTP status codes.
- GraphQL: a response can hold both
dataanderrors. The status can still be 2xx. Source 5সোর্স 5 - gRPC: a status code and an optional message. Source 8সোর্স 8
Best fit
- REST: Tutorial's view: resource-style APIs where caching and many different clients matter.
- GraphQL: Tutorial's view: clients that need different shapes of the same data.
- gRPC: Tutorial's view: calls between services, and calls that stream.
The REST interface has costs. Fielding writes that it lowers efficiency. He also writes that it is not optimal for kinds of interaction other than large-grain hypermedia transfer. Source 1সোর্স 1 A cache can also lower reliability when its old data differs a lot from the server's data. Source 1সোর্স 1
বাংলা ব্যাখ্যা
প্রতিটি পয়েন্টে হয় একটি রেফারেন্স (cite) আছে, নয়তো তা "টিউটোরিয়ালের মত" (Tutorial's view) দিয়ে শুরু। "টিউটোরিয়ালের মত" মানে এটি টিউটোরিয়ালের নিজের মূল্যায়ন।
এটি কী
- REST: কনস্ট্রেইন্ট সহ একটি আর্কিটেকচারাল স্টাইল। Source 1সোর্স 1
- GraphQL: একটি কোয়েরি ল্যাঙ্গুয়েজ এবং একটি সার্ভার-সাইড রানটাইম। Source 2সোর্স 2
- gRPC: একটি রিমোট সার্ভারের মেথড লোকালের মতো কল করার উপায়। Source 7সোর্স 7
কন্ট্রাক্ট কোথায় থাকে
- REST: টিউটোরিয়ালের মত: কোনো একটি স্কিমা ফাইল নেই। চুক্তিটি হলো ইউনিফর্ম ইন্টারফেস, যার মধ্যে আছে রিসোর্স, রিপ্রেজেন্টেশন ও মিডিয়া টাইপ।
- GraphQL: টাইপ ও ফিল্ডের স্কিমায়। Source 4সোর্স 4
- gRPC: একটি সার্ভিস ডেফিনিশনে, ডিফল্টভাবে একটি
.protoফাইলে। Source 8সোর্স 8
নেটওয়ার্কে ডেটা (data on the wire)
- REST: কোনো একটি মিডিয়া টাইপে একটি রিপ্রেজেন্টেশন। Source 1সোর্স 1
- GraphQL: ক্লায়েন্ট ও সার্ভারের JSON সমর্থন করা উচিত। Source 5সোর্স 5
- gRPC: ডিফল্টভাবে Protocol Buffers। অন্য ফরম্যাটও সম্ভব। Source 7সোর্স 7
সম্পর্কিত ডেটা
- REST: ডেটা একটি স্ট্যান্ডার্ড রূপে যায়, প্রতিটি অ্যাপ্লিকেশনের জন্য মাপা রূপে নয়। এতে দক্ষতা কমতে পারে। Source 1সোর্স 1
- GraphQL: একটি কোয়েরি একটি রিকুয়েস্টে সম্পর্কিত ডেটা আনতে পারে। Source 3সোর্স 3
- gRPC: টিউটোরিয়ালের মত: একটি মেথড তা-ই ফেরত দেয়, যা এর মেসেজ টাইপ সংজ্ঞায়িত করে। তাই সম্পর্কিত ডেটা সার্ভিসের একটি ডিজাইন পছন্দ।
ক্যাশিং
- REST: একটি ক্যাশ কনস্ট্রেইন্ট। রিট্রিভাল রেসপন্স ডিফল্টভাবে ক্যাশযোগ্য। Source 1সোর্স 1
- GraphQL: URL-এর মতো কোনো ইউনিক আইডি নেই। তাই ক্লায়েন্ট ক্যাশিংয়ের জন্য API-কে আইডি প্রকাশ করা উচিত। Source 6সোর্স 6 কোয়েরির জন্য GET HTTP ও CDN ক্যাশিংয়ে সাহায্য করতে পারে। কিন্তু লম্বা কোয়েরি URL-এর সীমা পার করতে পারে। Source 5সোর্স 5
- gRPC: টিউটোরিয়ালের মত: এখানে ব্যবহৃত gRPC পেজগুলো রেসপন্স ক্যাশিং বর্ণনা করে না। তাই টিমের ডিজাইন দেখে নিন।
স্ট্রিমিং ও পুশ
- REST: টিউটোরিয়ালের মত: এই পেজের বাইরে। পরের পেজে লং পোলিং, WebSockets ও SSE আছে।
- GraphQL: সাবস্ক্রিপশন একটি অপারেশন টাইপ। Source 3সোর্স 3
- gRPC: সার্ভার, ক্লায়েন্ট ও বাইডিরেকশনাল স্ট্রিমিং। Source 8সোর্স 8
এরর
- REST: টিউটোরিয়ালের মত: এটি ব্যবহৃত প্রোটোকলের ওপর নির্ভর করে, প্রায়ই HTTP স্ট্যাটাস কোড।
- GraphQL: একটি রেসপন্সে
dataওerrorsদুটোই থাকতে পারে। স্ট্যাটাস তবু 2xx হতে পারে। Source 5সোর্স 5 - gRPC: একটি স্ট্যাটাস কোড এবং একটি ঐচ্ছিক মেসেজ। Source 8সোর্স 8
সবচেয়ে মানানসই
- REST: টিউটোরিয়ালের মত: রিসোর্স-স্টাইল API, যেখানে ক্যাশিং ও অনেক আলাদা ক্লায়েন্ট গুরুত্বপূর্ণ।
- GraphQL: টিউটোরিয়ালের মত: যে ক্লায়েন্টদের একই ডেটার আলাদা আলাদা আকার লাগে।
- gRPC: টিউটোরিয়ালের মত: সার্ভিসের মধ্যে কল এবং যে কল স্ট্রিম করে।
REST ইন্টারফেসের খরচ আছে। Fielding লেখেন যে এটি দক্ষতা কমায়। তিনি আরও লেখেন, বড় আকারের হাইপারমিডিয়া ট্রান্সফার ছাড়া অন্য ধরনের ইন্টারঅ্যাকশনের জন্য এটি সবচেয়ে ভালো নয়। Source 1সোর্স 1 ক্যাশের পুরনো ডেটা সার্ভারের ডেটা থেকে অনেক আলাদা হলে ক্যাশ নির্ভরযোগ্যতাও কমাতে পারে। Source 1সোর্স 1
A real-life example
This example is the tutorial's own. An exam platform has an app that shows an exam, its teacher, and the score of a student.
- With a REST design, the app may ask for the exam, then the teacher, then the score, each at its own address. A cache can keep the exam and the teacher.
- With GraphQL, the app sends one query that names the fields it needs from all three. The answer has the same shape as the query.
- With gRPC, a grading service calls a
GetScoremethod on a scoring service, with typed messages. The app does not call it directly.
None of the three is "best". Each has a different price for the same job.
সহজ English
This example is the tutorial's own. An exam platform has an app. The app shows an exam, its teacher, and the score of a student.
- With a REST design, the app may ask for the exam, then the teacher, then the score. Each has its own address. A cache can keep the exam and the teacher.
- With GraphQL, the app sends one query. The query names the fields it needs from all three. The answer has the same shape as the query.
- With gRPC, a grading service calls a
GetScoremethod on a scoring service. It uses typed messages. The app does not call it directly.
None of the three is "best". Each has a different price for the same job.
বাংলা ব্যাখ্যা
এই উদাহরণটি টিউটোরিয়ালের নিজের। একটি পরীক্ষার প্ল্যাটফর্মের একটি অ্যাপ আছে। অ্যাপ একটি পরীক্ষা, তার শিক্ষক এবং একজন শিক্ষার্থীর স্কোর দেখায়।
- REST ডিজাইনে অ্যাপ হয়তো প্রথমে পরীক্ষা চায়, তারপর শিক্ষক, তারপর স্কোর। প্রতিটির নিজস্ব অ্যাড্রেস আছে। একটি ক্যাশ পরীক্ষা ও শিক্ষককে রাখতে পারে।
- GraphQL-এ অ্যাপ একটি কোয়েরি পাঠায়। কোয়েরি তিনটির থেকেই দরকারি ফিল্ডের নাম দেয়। উত্তরের আকার কোয়েরির আকারের মতোই।
- gRPC-তে একটি গ্রেডিং সার্ভিস একটি স্কোরিং সার্ভিসের
GetScoreমেথড কল করে। এটি টাইপযুক্ত (typed) মেসেজ ব্যবহার করে। অ্যাপ সরাসরি এটি কল করে না।
তিনটির কোনোটিই "সবচেয়ে ভালো" নয়। একই কাজের জন্য প্রতিটির দাম আলাদা।
Common mistakes
- Calling every JSON-over-HTTP API "REST". REST is a set of constraints, including the uniform interface Source 1সোর্স 1, and it is not tied to one protocol Source 1সোর্স 1.
- Checking only the HTTP status of a GraphQL call. A response with data and errors can still have status 2xx Source 5সোর্স 5. Read the
errorskey Source 3সোর্স 3. - Thinking GraphQL replaces the database. It is not tied to any database or storage engine Source 2সোর্স 2.
- Thinking both sides of a gRPC call agree. The client and the server judge the call on their own, and the results may not match Source 8সোর্স 8. Changes made before a cancel are not rolled back Source 8সোর্স 8.
সহজ English
- Calling every JSON-over-HTTP API "REST". REST is a set of constraints, including the uniform interface. Source 1সোর্স 1 It is not tied to one protocol. Source 1সোর্স 1
- Checking only the HTTP status of a GraphQL call. A response with data and errors can still have status 2xx. Source 5সোর্স 5 Read the
errorskey. Source 3সোর্স 3 - Thinking GraphQL replaces the database. It is not tied to any database or storage engine. Source 2সোর্স 2
- Thinking both sides of a gRPC call agree. The client and the server judge the call on their own. The results may not match. Source 8সোর্স 8 Changes made before a cancel are not rolled back. Source 8সোর্স 8
বাংলা ব্যাখ্যা
- প্রতিটি JSON-over-HTTP API-কে "REST" বলা। REST হলো কিছু কনস্ট্রেইন্টের সমষ্টি, যার মধ্যে ইউনিফর্ম ইন্টারফেস আছে। Source 1সোর্স 1 এটি কোনো একটি প্রোটোকলে বাঁধা নয়। Source 1সোর্স 1
- GraphQL কলের শুধু HTTP স্ট্যাটাস দেখা। ডেটা ও এরর থাকা একটি রেসপন্সের স্ট্যাটাস তবু 2xx হতে পারে। Source 5সোর্স 5
errorsকী (key) পড়ুন। Source 3সোর্স 3 - ভাবা যে GraphQL ডেটাবেসের জায়গা নেয়। এটি কোনো ডেটাবেস বা স্টোরেজ ইঞ্জিনের সাথে বাঁধা নয়। Source 2সোর্স 2
- gRPC কলের দুই পক্ষ একমত ভাবা। ক্লায়েন্ট ও সার্ভার কলটি নিজ নিজ মতো বিচার করে। ফলাফল না-ও মিলতে পারে। Source 8সোর্স 8 ক্যানসেলের আগে করা পরিবর্তন রোলব্যাক হয় না। Source 8সোর্স 8
What a tester can check
Tutorial advice
These test ideas are the tutorial's own advice, not a claim of the sources.
- REST: Send a request with no earlier session and check that the server understands it. Check which responses may be cached.
- GraphQL: Read both
dataanderrorsin each response, not only the status code. Ask for a field that this user must not see, and check what comes back. - gRPC: Set a very short deadline and check for
DEADLINE_EXCEEDED. Then check whether the server still did the work. Cancel a call in the middle and check for half-finished changes. - Contract: When the schema or the
.protofile changes, run the old client against the new server.
সহজ English
Tutorial advice
These test ideas are the tutorial's own advice. They are not a claim of the sources.
- REST: Send a request with no earlier session. Check that the server understands it. Check which responses may be cached.
- GraphQL: Read both
dataanderrorsin each response, not only the status code. Ask for a field that this user must not see. Check what comes back. - gRPC: Set a very short deadline. Check for
DEADLINE_EXCEEDED. Then check whether the server still did the work. Cancel a call in the middle. Check for half-finished changes. - Contract: When the schema or the
.protofile changes, run the old client against the new server.
বাংলা ব্যাখ্যা
Tutorial advice
এই টেস্ট ধারণাগুলো টিউটোরিয়ালের নিজের পরামর্শ। এগুলো সোর্সগুলোর দাবি নয়।
- REST: আগের কোনো সেশন ছাড়া একটি রিকুয়েস্ট পাঠান। দেখুন, সার্ভার এটি বোঝে কি না। কোন রেসপন্স ক্যাশ করা যেতে পারে, তা দেখুন।
- GraphQL: প্রতিটি রেসপন্সে শুধু স্ট্যাটাস কোড নয়,
dataওerrorsদুটোই পড়ুন। এমন একটি ফিল্ড চান, যা এই ইউজারের দেখার কথা নয়। কী ফেরত আসে দেখুন। - gRPC: খুব ছোট একটি ডেডলাইন ঠিক করুন।
DEADLINE_EXCEEDEDআছে কি না দেখুন। তারপর দেখুন, সার্ভার তবু কাজটি করেছে কি না। একটি কল মাঝপথে ক্যানসেল করুন। আধা-শেষ পরিবর্তন আছে কি না দেখুন। - কন্ট্রাক্ট: স্কিমা বা
.protoফাইল বদলালে পুরনো ক্লায়েন্ট নতুন সার্ভারের সাথে চালান।
Key words
| Word | Meaning |
|---|---|
| Resource | Any information that can be named, as a mapping to a set of values Source 1সোর্স 1 |
| Representation | Bytes plus metadata that describe them, sent to show or change a resource Source 1সোর্স 1 |
| Uniform interface | The REST constraint that sets it apart from other styles, with four sub-constraints Source 1সোর্স 1 |
| Stateless | Each request holds all the information needed to understand it Source 1সোর্স 1 |
| Schema | The set of types and fields that a GraphQL service offers Source 4সোর্স 4 |
| Query | A GraphQL operation that reads data, starting at a root type Source 3সোর্স 3 |
| Mutation | A GraphQL operation type, listed with query and subscription Source 3সোর্স 3 |
| Protocol Buffers | The default way for gRPC to define and serialize messages Source 7সোর্স 7 |
| Stub | The client-side object that has the same methods as the service Source 8সোর্স 8 |
| Unary RPC | A gRPC call with one request and one response Source 8সোর্স 8 |
| Deadline | The time a gRPC client will wait before the call ends with DEADLINE_EXCEEDED Source 8সোর্স 8 |