原文:https://hackernoon.com/rest-in-peace-grpc-for-micro-service-and-grpc-for-the-web-a-how-to-908cc05e1083

https://stackoverflow.com/questions/43682366/how-is-grpc-different-from-rest

------------------------------------------------------

REST is not the Best for Micro-Services GRPC and Docker makes a compelling case

June 7th 2017

For quite a long time, when Service Oriented Architecture (SOA) and WebService were the talk of the tech town, most of the software systems were built using SOAP and related WSDL technology. I was involved in multiple projects built using SOAP technology. I started first dabbling with REST when faced with the need to create a quick prototype northbound/external interface for a system.

I, like many others, fell in love with REST immediately ;more so after reading more about it, in the jewel of a paper (Architectural Styles and the Design of Network-based Software Architectures,) by Roy Fielding -principal author of HTTP protocol and consequently founder of the World Wide Web based on the internet. Soon along came JSON; and REST and JSON quickly replaced the cumbersome inefficient SOAP and associated WSDL in building out Service Oriented Architectures.

Programs or other components could now easily talk to each other efficiently through firewalls over HTTP; just like SOAP but much more efficiently. More so the versioning in WSDL, or the lack of it, and the problems it causes when modifying, or slightly extending a published interface, all but vanished. Though a lot of Web Services still uses SOAP, most new development and especially software systems became internally composed of REST based services.

RESTful architecture is what the world wide web is based on. It is as relevant to that context now, as it was when HTTP was designed. But for composing software systems by modern software development teams, there are better technologies that are available now.

Protobuffer was the technology Google was using for long, along with GRPC , in its software ecosystem — one of the largest micro service ecosystems in the world. Google open sourced GRPC in 2015.

Though few companies will operate at this scale, this is a technology that is very relevant in most enterprise SW; with globally distributed teams, working over different time-zones, languages and cultures. A strongly typed and versioned interface helps a lot in the SW development in such companies and generally even across multiple teams.

While technologies like Protobuffer and GRPC are unambiguous in their implementations, the term micro-service reminds me loosely of the SOA acronym. Other than people very close to SW development, to many this terms is confusing. However this is not just a hype promoted by commercial SW vendors. Many companies like Netflix have started using Micro Servicesas a way to compose SW systems successfully.

What makes a Service in SOA a Microservice ? Maybe to get a context of what a micro-service is, you may need to know a little about the Why Micro-Service part

Basically, a microservice does fewer things, a lot of excellent articles are written regarding micro-services, but more than what it is, is what it frees; developers are not constrained to add features to the existing services blowing up the best thought of services into a behemoth over time. Developers have more control and flexibility of the system they are building.

The advent and wide adoption of easy to use container technology like Docker has a lot to do with the success of microservice. Usually microservice systems are implemented as a set of Docker containers.The immutable Docker layers concept, and easy composition via DockerFile, has really taken the OpenClosedPrinciple from a source code structuring practice that few knew and followed, to wide adoption by applying the principle to the executable, the binary level. A released Docker image is immutable, it is closed for all modifications. Having a good versioning strategy for the images ensures that, what is released, stays forever immutable and extension can be released as a different image, with a different version.

Here are some of the top reasons which have attracted me to use GRPC and Protobuffer technology in micro-services.

1. Static Typed & Versioned Interface between Components

Have you ever missed while working in REST, the strongly typed interfaces of distributed technology that had come and gone over the years COM , CORBA IDL’s and SOAP’s WSDL ? Neither have I; barely noticed, maybe a bit glad of not needing to do or deal with the monstrosity of WSDL’s code generation and allied; at least not until the lack of type deficiency began to show on SW development and integration in a multi-team, multi-component system. Here the lack of a strong versioned typed interface gave to all sorts of coding horrors; miscommunication and mistrust between disparate distributed teams.

2. Efficiency & Stability

REST and JSON were way more efficient than the XML heavy SOAP payloads that get passed around between Web Services. GRPC uses Protobuffer for binary serialization of messages, which gives a lot more efficiency when compared to textual JSON used by REST. Also, GRPC works on HTTP/2.0 protocol, unlike most REST libraries which implicitly use the ubiquitous HTTP /1.1. HTTP/2.0 is multiplexed, has header compression and is way more efficient than HTTP/1.1. Till I started using and reading about GRPC, I did not even knew about HTTP/2 and the efficiency it offered.

3. Polygot Programming

GRPC and Protobuffer are available in popular languages like C++, Java, Node.js (Typescript), Go among others. This gives tremendous flexibility in building a system. For example, for some computer vision based tasks that require CPU, GPU resources, you can power-up a C++ -GRPC based micro-service, that interfaces with a Go based micro-service and a TypeScript based micro-service. In practice, composing a software system with the flexibility to use the right programming language is a pretty good advantage.

4. Request-Response Streaming, message-queue

There are many other reasons too. One example that I find pretty intriguing and testing out in production is the streaming part; you can either have the request streamed, the response streamed, or both request and responses streamed over. This is making the message queue implementations or Akka based remote actors obsolete, for many of the asynchronous message based communication that happens in a software system.

5. Almost Serverless

The other being the fact that the GRPC implementation is as server-less as you can get, without going full serverless. That is you don’t need Java’s Jetty/Jersey/Tomcat/Jboss (in the increasing order of server-side thickness), Scala’s Spray (and accompanying DSL monstrosity), C++ nothing/G-SOAP ? or any other full-fledged server or embedded servers. GRPC server library implementation in most of the languages I have tried seems to be mature and ripe for production. And you barely notice. It is almost like serverless, without having to sell your soul to the ‘server provider’. And the server in it is the efficient, multiplexed HTTP/2 based server.

However this same use of HTTP/2 is one sticking problem in adoption. This means that unlike REST, you cannot just type the GRPC API in browser view and expect it to work. So this integration with front-end is usually a problem that sticks out. There are options to work around that, one having a backend for front end component, to orchestrate among the multiple back-end micro-services and expose a REST API for the GUI layer. The other is using a proxy to proxy the HTTP/2 based GRPC to HTTP/1.1 via grpc-web. I have written a how-to for the latter part. You can read about this here.

Update: August 2018

A blog post I found was mirroring the exact same problems regarding the problems of Interface Semantics with REST. Other than experiencing this yourself with time, or reading about it from other peoples experience, it is hard to prove or disprove design decisions.

Our existing systems have traditionally used REST APIs with JSON payloads for communicating synchronously. This choice was made based on the overwhelming maturity, familiarity, and tooling available, but as our cross-continent engineering teams grew, we needed to design a consistent, agreed upon RESTful API. …Eventually, the complications with our REST API led us to search out alternatives https://blog.bugsnag.com/grpc-and-microservices-architecture/

REST is not the Best for Micro-Services GRPC and Docker makes a compelling case的更多相关文章

  1. 微服务 Micro services

    微服务 (Microservices) 是一种软件架构风格,它是以专注于单一责任与功能的小型功能区块 (Small Building Blocks) 为基础,利用模组化的方式组合出复杂的大型应用程序, ...

  2. 安装composer slim(php web api micro services)

    1. 安装php7 2. 下载 https://getcomposer.org/composer.phar 3. 开启ssh, 在 php.ini中.extension=C:\Program File ...

  3. Secure services with TLS ---Docker配置https

    官方文档:https://docs.docker.com/ee/ucp/interlock/usage/tls/

  4. 【Linux】【Services】【Docker】Docker File

    Docker Images: docker commit Dockerfile:文本文件,镜像文件构建脚本: Dockerfile:由一系列用于根据基础镜像构建新的镜像文件的专用指令序列组成: 指令: ...

  5. 【Linux】【Services】【Docker】网络

    容器的网络模型: closed container: 仅有一个接口:loopback 不参与网络通信,仅适用于无须网络通信的应用场景,例如备份.程序调试等: --net none bridged co ...

  6. 【Linux】【Services】【Docker】应用

    1. Docker应用: 镜像:包含了启动Docker容器所需要的文件系统层级及其内容:基于UnionFS采用分层结构实现: bootfs,rootfs registry:保存docker镜像及镜像层 ...

  7. 【Linux】【Services】【Docker】基础理论

    1. 名称空间:NameSpace 内核级别,环境隔离: 1.1. 名称空间的历史 PID NameSpace:Linux 2.6.24 ,PID隔离 Network NameSpace:Linux ...

  8. Micro Frontends & microservices

    Micro Frontends & microservices https://micro-frontends.org/ https://github.com/neuland/micro-fr ...

  9. Docker入门(四):服务(Services)

    这个<Docker入门系列>文档,是根据Docker官网(https://docs.docker.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指 ...

随机推荐

  1. Yii2性能优化

    https://www.yiiframework.com/doc/guide/2.0/zh-cn/tutorial-performance-tuning 性能优化 有许多因素影响你的 Web 应用程序 ...

  2. php面向对象(目录操作)

    目录操作 创建目录 Mkdir(目录地址,权限,是否递归创建=false); Rmdir(目录地址) 删除目录 仅仅可以删除空目录.(不支持递归删除) 移动(改名) Rename(旧地址,新地址) 该 ...

  3. EFCore中的导航属性

    使用了这么久的EntityFrameworkCore框架,今天想来就其中的一个部分来做一个知识的梳理,从而使自己对于整个知识有一个更加深入的理解,如果你对EFCore中的实体关系不熟悉你需要有一个知识 ...

  4. 面向对象分析与设计—OOD部分

    第三部分 面向对象设计 3.1 面向对象设计(OOD)的定义? 在面向对象分析阶段,已经针对用户需求建立起用面向对象概念描述的系统分析模型.在设计阶段,要考虑为实现系统而采用的计算机设备.操作系统.网 ...

  5. page分页问题,根据页码获取对应页面的数据,接口调用

    添加一个log.js文件,进行接口调用. import axios from '@/libs/api.request' const MODULE_URL = '/log'; export const ...

  6. WUSTOJ 1326: Graph(Java)费马数

    题目链接:1326: Graph 参考博客:HNUSTOJ-1617 Graph(费马数)--G2MI Description Your task is to judge whether a regu ...

  7. 二十三、uevnet机制和U盘自动挂载

    一.uevent机制 在分析之前,我们首先要知道uevent作用是什么.在此我们先来看一个uevent机制的框架图: 该图片来自:Linux设备模型(3)_Uevent 通过图片我们可以确定ueven ...

  8. myisam和innodb的区别,java事务不起作用原因

    myisam:只支持表级锁.不支持事务.方便移植.该类型是mysql默认表存储类型 innodb:支持表级锁和行级锁.支持事务. 如果你的事务不起作用,很可能是用了myisam存储引擎,检查数据表引擎 ...

  9. jQuery AJAX基础

    一.JSON 定义:             JSON(JavaScript Object Notation, JS对象标记)是一种轻量级的数据交换格式.         它基于 ECMAScript ...

  10. 【转载】 C#中使用Count方法获取List集合中符合条件的个数

    很多时候操作List集合的过程中,我们需要根据特定的查询条件,获取List集合中有多少个实体对象符合查询条件,例如一批产品的对象List集合,如果这批产品的不合格数量大于10则重点备注.在C#中可以自 ...