Upgrade to Pro — share decks privately, control downloads, hide ads and more …

REST API vs gRPC, Which One Should You Use in B...

REST API vs gRPC, Which One Should You Use in Breaking a Monolith [DevConf 2018]

You heard of “new thing” called gRPC and promises that it will solve all issues for you, so now you are not sure if you should use it for breaking up your monolith to Microservices. If it is good for Google it should be good for you also right?On the other hand, you have been using REST API’s for some time now, at least as a consumer, so maybe this would be better approach in Microservices waters, or would it?

Which one to chose and which one will fit your use case better?

Join me in this talk were I will try to explain both approaches, good and bad. I will give some points and tips, which will help you in understanding better which one will be better for you. By doing this I will also share some best practices for both approaches.

Vladimir Dejanovic

September 28, 2018
Tweet

More Decks by Vladimir Dejanovic

Other Decks in Programming

Transcript

  1. @devconfpl @VladimirD_42 REST API vs gRPC Which One Should You

    Use in Breaking a Monolith Vladimir Dejanović @VladimirD_42
  2. @VladimirD_42 @devconfpl REST Cacheability Code on Demand (Optional) Layered System

    Statelessness Uniform Interface Client-Server Architecture
  3. @VladimirD_42 @devconfpl REST in Real Life import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.repository.query.Param;

    import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource(collectionResourceRel = "people", path = "people") public interface PersonRepository extends MongoRepository<Person, String> { List<Person> findByLastName(@Param("name") String name); }
  4. @VladimirD_42 @devconfpl REST in Real Life import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.repository.query.Param;

    import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource(collectionResourceRel = "people", path = "people") public interface PersonRepository extends MongoRepository<Person, String> { List<Person> findByLastName(@Param("name") String name); }
  5. @VladimirD_42 @devconfpl REST in Real Life import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.repository.query.Param;

    import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource(collectionResourceRel = "people", path = "people") public interface PersonRepository extends MongoRepository<Person, String> { List<Person> findByLastName(@Param("name") String name); }
  6. @VladimirD_42 @devconfpl REST in Real Life import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.repository.query.Param;

    import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource(collectionResourceRel = "people", path = "people") public interface PersonRepository extends MongoRepository<Person, String> { List<Person> findByLastName(@Param("name") String name); }
  7. @VladimirD_42 @devconfpl REST in Real Life import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.repository.query.Param;

    import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource(collectionResourceRel = "people", path = "people") public interface PersonRepository extends MongoRepository<Person, String> { List<Person> findByLastName(@Param("name") String name); }
  8. @VladimirD_42 @devconfpl REST vs gRPC Schema is “optional” in REST

    REST code or schema first gRPC is schema first
  9. @VladimirD_42 @devconfpl ... message TransferMoney { int32 trans_id = 1;

    int32 from_account_number = 2; int32 to_account_number = 3; double ammount = 4; string message = 5; } service Bank { rpc Transfer(TransferMoney) returns (TransferConfirmation); rpc ListenToNotifications(Account) returns (stream AccountNotification); rpc RequestTransfer(stream RequestMoney) returns (stream RequestStatus); } ...
  10. @VladimirD_42 @devconfpl ... message TransferMoney { int32 trans_id = 1;

    int32 from_account_number = 2; int32 to_account_number = 3; double ammount = 4; string message = 5; } service Bank { rpc Transfer(TransferMoney) returns (TransferConfirmation); rpc ListenToNotifications(Account) returns (stream AccountNotification); rpc RequestTransfer(stream RequestMoney) returns (stream RequestStatus); } ...
  11. @VladimirD_42 @devconfpl ... message TransferMoney { int32 trans_id = 1;

    int32 from_account_number = 2; int32 to_account_number = 3; double ammount = 4; string message = 5; } service Bank { rpc Transfer(TransferMoney) returns (TransferConfirmation); rpc ListenToNotifications(Account) returns (stream AccountNotification); rpc RequestTransfer(stream RequestMoney) returns (stream RequestStatus); } ...
  12. @VladimirD_42 @devconfpl ... message TransferMoney { int32 trans_id = 1;

    int32 from_account_number = 2; int32 to_account_number = 3; double ammount = 4; string message = 5; } service Bank { rpc Transfer(TransferMoney) returns (TransferConfirmation); rpc ListenToNotifications(Account) returns (stream AccountNotification); rpc RequestTransfer(stream RequestMoney) returns (stream RequestStatus); } ...
  13. @VladimirD_42 @devconfpl ... message TransferMoney { int32 trans_id = 1;

    int32 from_account_number = 2; int32 to_account_number = 3; double ammount = 4; string message = 5; } service Bank { rpc Transfer(TransferMoney) returns (TransferConfirmation); rpc ListenToNotifications(Account) returns (stream AccountNotification); rpc RequestTransfer(stream RequestMoney) returns (stream RequestStatus); } ...
  14. @VladimirD_42 @devconfpl ... message TransferMoney { int32 trans_id = 1;

    int32 from_account_number = 2; int32 to_account_number = 3; double ammount = 4; string message = 5; } service Bank { rpc Transfer(TransferMoney) returns (TransferConfirmation); rpc ListenToNotifications(Account) returns (stream AccountNotification); rpc RequestTransfer(stream RequestMoney) returns (stream RequestStatus); } ...
  15. @VladimirD_42 @devconfpl ... message TransferMoney { int32 trans_id = 1;

    int32 from_account_number = 2; int32 to_account_number = 3; double ammount = 4; string message = 5; } service Bank { rpc Transfer(TransferMoney) returns (TransferConfirmation); rpc ListenToNotifications(Account) returns (stream AccountNotification); rpc RequestTransfer(stream RequestMoney) returns (stream RequestStatus); } ...
  16. @VladimirD_42 @devconfpl ... message TransferMoney { int32 trans_id = 1;

    int32 from_account_number = 2; int32 to_account_number = 3; double ammount = 4; string message = 5; } service Bank { rpc Transfer(TransferMoney) returns (TransferConfirmation); rpc ListenToNotifications(Account) returns (stream AccountNotification); rpc RequestTransfer(stream RequestMoney) returns (stream RequestStatus); } ...
  17. @VladimirD_42 @devconfpl ... message TransferMoney { int32 trans_id = 1;

    int32 from_account_number = 2; int32 to_account_number = 3; double ammount = 4; string message = 5; } service Bank { rpc Transfer(TransferMoney) returns (TransferConfirmation); rpc ListenToNotifications(Account) returns (stream AccountNotification); rpc RequestTransfer(stream RequestMoney) returns (stream RequestStatus); } ...
  18. @VladimirD_42 @devconfpl ... message TransferMoney { int32 trans_id = 1;

    int32 from_account_number = 2; int32 to_account_number = 3; double ammount = 4; string message = 5; } service Bank { rpc Transfer(TransferMoney) returns (TransferConfirmation); rpc ListenToNotifications(Account) returns (stream AccountNotification); rpc RequestTransfer(stream RequestMoney) returns (stream RequestStatus); } ...
  19. @VladimirD_42 @devconfpl ... message TransferMoney { int32 trans_id = 1;

    int32 from_account_number = 2; int32 to_account_number = 3; double ammount = 4; string message = 5; } service Bank { rpc Transfer(TransferMoney) returns (TransferConfirmation); rpc ListenToNotifications(Account) returns (stream AccountNotification); rpc RequestTransfer(stream RequestMoney) returns (stream RequestStatus); } ...