Don't Use REST APIs in your Backend, Use gRPC

  Рет қаралды 37,580

CompSciGuy

CompSciGuy

Күн бұрын

Пікірлер: 52
@hakoda2616
@hakoda2616 Жыл бұрын
Computer science is crazy, I've never been able to study something without someone telling me "why are you using this? you should use this other one." Anyway thanks for the video, I had never heard of gRPC.
@pss_crs
@pss_crs Жыл бұрын
there's good chance this comment delivered by GRPC
@MrCompSciGuy
@MrCompSciGuy Жыл бұрын
Hope you liked it! I think at the end of the day it's all about tradeoffs. If you're just building something over the weekend that you'll never touch again. gRPC is probably overkill. It takes a slightly longer time to set up than a REST API - especially if you haven't used it before. But for any serious production workload if you gRPC doesn't at least come into the conversation at some point you'll probably end up paying a steep price down the road.
@ProtectedClassTest
@ProtectedClassTest Жыл бұрын
At the end of the day, these guys have their own agenda so your best bet would be to try out those popular things and see if you like it.. anddd i dont like grpc
@HemitPatel-s3f
@HemitPatel-s3f Ай бұрын
its rlly good! basically just like calling a function but the function is ran in another service (server) and you get the results back from that service
@abuDA-bt6ei
@abuDA-bt6ei Ай бұрын
why would you use gRPC? Use a restapi
@jamesrosemary2932
@jamesrosemary2932 Жыл бұрын
This is misleading. The API Rest example assumes that for each API request you have to write all the code to initialize, send and interpret the response. Which no one in their right mind would do. All the repetitive code is encapsulated in a class method and that's it. If there is a bug, there is only one place where it can happen and only one place to fix it. Exactly as it is done in the gRPC examples.
@MrCompSciGuy
@MrCompSciGuy Жыл бұрын
It's exaggerated to bring the point home. If my example would contain 5 layers of nested classes it'd be even less understandable than it is now. Frankly, unless you are generating your REST API from some OpenAPI spec (which is a ~reasonable way of using REST) you are still implicitly doing all the same logic at some layer in your code. At some point you are: 1. Specifying either a class or dictionary that contains the request body. 2. Specifying either a class or dictionary that you expect will match what the server responds with. 3. Specifying your URL path and any parameters. 1 and 2 implicitly are serialized or deserialized (you only hide the actual call to the JSON parsing -> all the same things might still go wrong). And you might still accidentally change the name of a variable on your server causing that to propagate through your code to change what is returned in the response body. The main benefit with gRPC (at small scale), which maybe didn't come through in the video, is the contract it provides that you know the server will abide by. Sure, you could probably build something similar yourself. But it'd eventually just be a bad reimplementation of gRPC, and why would you waste your time on that when you can just use it off the shelf and focus on actual business problems? When scale start mattering, then gRPC (or something similar) becomes a no brainer. Otherwise you're just be wasting money on inefficient serialization formats.
@just-squirrels
@just-squirrels Жыл бұрын
Contracts aren't what make gRPC a great solution for certain problems - all interfaces require a contract of some sort, even HTTP + JSON. The thing that sets gRPC apart from HTTP + JSON is performance. It serializes and deserializes faster, and uses less data on the wire.
@JiggyJones0
@JiggyJones0 Жыл бұрын
@@MrCompSciGuy You should ONLY use gRPC over rest if data compression is the overriding concern. Very few applications require the extreme message compression that Protocol buffers can deliver. If flexibility and decoupling is what you need, which is most applications, then go with REST. Remote procedure calls are an obsolete and less flexible alternative to REST messaging. Distributed cloud-capable applications are easier to design and implement with a message passing metaphor than with a networked implementation of the old C function call. RPCs are strictly point to point and are not typically amenable to real-time redirection for load balancing or when network failures occur. To say that gRPC should be used when you need to scale is to show a fundamental misunderstand of gRPC and REST based architectures. gRPC does not scale well because of tight coupling.
@dreambuffer
@dreambuffer Жыл бұрын
​@@just-squirrels You can achieve most of the performance gains by using protobuf alone, the performance comes mostly from the tightly packed universal serialisation format, not from gRPC.
@just-squirrels
@just-squirrels Жыл бұрын
@@dreambuffer that’s a great callout!
@f135ta
@f135ta Жыл бұрын
The most horrific code i've ever seen. Thank god I dont have to work on that project
@clusterdriven
@clusterdriven 6 ай бұрын
A backend in python will never be fast anyways 😂. Just teasing. Thank you for this grpc lesson
@jaspervandijk27
@jaspervandijk27 10 ай бұрын
2:43 A lot of boiler plate. So what do we do? We write a lot of gRPC boilerplate to replace the boiletplate. What else could we have done? Write a more generic way of sending requests to your api, or "helper" functions for each request in their own class or util containing most requests in their own respective function that just return the data or anything that is needed based of the request.
@diegocastaneda4325
@diegocastaneda4325 7 ай бұрын
Your generic approach literally sounds like the gRPC implementation lol
@Ryan-xq3kl
@Ryan-xq3kl 2 ай бұрын
@@diegocastaneda4325except that its not and its just a rational way to implement REST
@slotos
@slotos 11 ай бұрын
Have you read REST dissertation in the first place? Using words “you are actually invoking a remote procedure call” is borderline insane and reeks of ignorance. REST API can utilize protobufs if you so desire, for crying out loud. It doesn’t dictate exchange format. What it does dictate, however, is to _not call remote functions_.
@HemitPatel-s3f
@HemitPatel-s3f Ай бұрын
this is perfect! im creating an ai mircoservice for my app and this technology would be perfect as the ai mircoservice is called upon by my main api to get the closest coordinates based on a list.
@mykyar9142
@mykyar9142 9 ай бұрын
Why are you talking about the REST API, but showing the HTTP JSON API? What the hell?
@elalemanpaisa
@elalemanpaisa 6 күн бұрын
he talks about performance and uses python as the server.. oh yea.. i love it already
@purpinkn
@purpinkn 2 ай бұрын
"That's a lot of boilerplate" *rewrites in Java* Okay bro
@theerrornan4456
@theerrornan4456 10 ай бұрын
You have some serious skill issues there using REST. You are writing Python in 90s way.
@michael_ibeh
@michael_ibeh 3 ай бұрын
too much code for this gRPC thingy, i'm stickig to REST all day.
@Koroistro
@Koroistro 2 ай бұрын
That assumes that management would allow it, but management believes that REST is the way to go. You don't buy Gucci bags because you need and handbag do you?
@mdrashidhussain1815
@mdrashidhussain1815 9 ай бұрын
nothing in CS is straight A. It all comes with its own compromises You any day need APIs like rest/gql however you try. You have to send data yo some client
@drygordspellweaver8761
@drygordspellweaver8761 9 ай бұрын
subliminal messaging worked. I subbed
@Jigad-e8y
@Jigad-e8y 12 күн бұрын
Gonzalez Sarah Perez Kevin Davis Robert
@yash1152
@yash1152 10 ай бұрын
1:35 whoooo in the world inspired you to use morph animation on code?? 3:59 🤦‍♀ as beautiful as the concepts taught in the video can be, the animations choice is absolutely worst. be simple man - just a plain "record edits on code & play on reverse" is far far better than these "mind boggling" - "eye twister" hodgepodge 😭
@DaveThomson
@DaveThomson Жыл бұрын
My backend (python) acts mostly as a client to fetch data from different 3rd party endpoints which are all REST and I dont control. My frontend is decoupled and, in a different language, react. So, how would gRPC help in this case? The only opportunity for me to use gRPC is if a) i can use between my frontend and backend or b) i have calls in my backend that consume endpoints in the backend API. Currently, there are none. My api is not public.
@DaveThomson
@DaveThomson Жыл бұрын
just an update, I realized I can run multiple services in my backend and then I can have the api endpoints in my backend use gRPC to work with backend services - kind of like an api gateway
@MrCompSciGuy
@MrCompSciGuy Жыл бұрын
Well for you it seems like you're talking about frontend -> backend. And there imo it kind of makes sense to use REST. Mainly because doing frontend -> backend with gRPC is a bit of a pain. Especially in this case, it seems like you have your backend which is basically 1 or 2 endpoints. And all they do is some business logic + call other REST endpoints. Whenever you migrate something, you have to compare the cost vs benefit you gain. In this case, it doesn't seem like you would gain a lot. Just make sure to keep your REST API simple (and that should generally be the rule you go for, keep it simple). gRPC really only starts simplifying when you get larger apps or very performance intensive ones.
@Ryan-xq3kl
@Ryan-xq3kl 2 ай бұрын
ill never take advice from people who use windows software willingly
@MuslimaAhamed-w8q
@MuslimaAhamed-w8q Күн бұрын
Thomas Charles Jackson Larry Davis Jessica
@DeanWilson-i8c
@DeanWilson-i8c 9 күн бұрын
Moore Patricia Moore Elizabeth Walker Donna
@jongxina3595
@jongxina3595 7 ай бұрын
Dont use grpc in your backend. Use graphql.
@shastri3303
@shastri3303 Жыл бұрын
Okay, now I have to rewrite my backend for the 5th time.🫠
@JiggyJones0
@JiggyJones0 Жыл бұрын
You have a lot to learn my friend. RPCs are an archaic technology. Software engineering has outgrew it. First of all gRPC forces a tight coupling between the components involved. We've learned to avoid tight coupling for a reason. It is a fundamental principle of microservices architecture. It is painful to watch developers make the same mistakes over and over again. JSON didn't exist when Roy Fielding wrote his dissertation on REST, but it is a useful "self-defining" message syntax. Protocol Buffers are anything but self-defining and require a complex system for distributed schema management to work at all. That may be justifiable if data compression is the overriding concern, but it makes loosely-coupled microservices impossible to implement. A properly designed RESTful solution is a far better match for the implementation of microservices architecture which is what MOST web services are today. Remote procedure calls are an obsolete and less flexible alternative to REST messaging. Distributed cloud-capable applications are easier to design and implement with a message passing metaphor than with a networked implementation of the old C function call. RPCs are strictly point to point and are not typically amenable to real-time redirection for load balancing or when network failures occur.
@colin398
@colin398 Жыл бұрын
Nobody can even agree on what is REST and what is not
@MrCompSciGuy
@MrCompSciGuy Жыл бұрын
I have to say. I disagree with every single point you made. > First of all gRPC forces a tight coupling It really doesn't enforce more tight coupling than REST. It just prevents you from accidentally messing up the server client contract. If anything, it gives your microservices a well-defined interface and that will in the long run be to your benefit. > implementation of microservices architecture which is what MOST web services are today Are you really sure about that? I'd claim that most serious applications in the industry today use some sort of RPC. Even if they don't use something open source they'l have implemented their own version. Of course, then you also have your message passing interfaces as well. But it's impossible to work at any scale without contracts, you'll go under in downtime. > Distributed cloud-capable applications are easier to design and implement with a message passing metaphor than with a networked implementation of the old C function call I agree that for a lot of cases you should probably use message passing instead. But REST is as much message passing as gRPC, and even if doing message passing, having your messages be a protobuf is still going to give you better typing. > and are not typically amenable to real-time redirection for load balancing or when network failures occur This is just straight up false. You don't think Google (which have used RPCs basically their entire history) face network failures or dynamic load balancing (when they probably have the world's most advanced load balancer with Slicer, which is a very interesting paper that I'd recommend you read).
@stivvits1067
@stivvits1067 Жыл бұрын
To go truly loosely couple with your backends you better use message queues
@dreambuffer
@dreambuffer Жыл бұрын
protobuf != gRPC. gRPC is only built on top of protobuf, but you can use protobuf by itself very simply and at very little cost. It doesn't enforce a style or framework onto your codebase for the most part, the only condition is that you need a compiler and a library to deserialise. Other than that it can be treated almost the same as JSON or similar.
@maowtm
@maowtm 10 ай бұрын
​@@dreambuffernot exactly the same. The great thing about JSON is that data is human readable and self describing, which is huge for debugging
tRPC, gRPC, GraphQL or REST: when to use what?
10:46
Software Developer Diaries
Рет қаралды 82 М.
REST vs RPC vs GraphQL API - How do I pick the right API paradigm?
15:36
Nastya and balloon challenge
00:23
Nastya
Рет қаралды 58 МЛН
Как мы играем в игры 😂
00:20
МЯТНАЯ ФАНТА
Рет қаралды 3 МЛН
Что такое gRPC и Protobuf?
8:37
Merion Academy
Рет қаралды 51 М.
Don't Use Websockets (Until You Try This…)
6:46
Code With Ryan
Рет қаралды 303 М.
Are we going back to PHP with fullstack JavaScript?
9:57
Maximilian Schwarzmüller
Рет қаралды 141 М.
The Right Way To Build REST APIs
10:07
Awesome
Рет қаралды 103 М.
Что такое RPC и gRPC за 10 минут
11:01
Listen IT
Рет қаралды 71 М.
The Hidden Cost Of GraphQL And NodeJS
28:35
ThePrimeTime
Рет қаралды 192 М.
Where should you use gRPC? And where NOT to use it!
10:57
CodeOpinion
Рет қаралды 82 М.
Adding a cache is not as simple as it may seem...
13:29
Dreams of Code
Рет қаралды 108 М.
GRPC - بالعربي
22:41
pragma
Рет қаралды 14 М.
Node.js is a serious thing now… (2023)
8:18
Code With Ryan
Рет қаралды 648 М.