REST is not the Best for Micro-Services GRPC and Docker makes a compelling case
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
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的更多相关文章
- 微服务 Micro services
微服务 (Microservices) 是一种软件架构风格,它是以专注于单一责任与功能的小型功能区块 (Small Building Blocks) 为基础,利用模组化的方式组合出复杂的大型应用程序, ...
- 安装composer slim(php web api micro services)
1. 安装php7 2. 下载 https://getcomposer.org/composer.phar 3. 开启ssh, 在 php.ini中.extension=C:\Program File ...
- Secure services with TLS ---Docker配置https
官方文档:https://docs.docker.com/ee/ucp/interlock/usage/tls/
- 【Linux】【Services】【Docker】Docker File
Docker Images: docker commit Dockerfile:文本文件,镜像文件构建脚本: Dockerfile:由一系列用于根据基础镜像构建新的镜像文件的专用指令序列组成: 指令: ...
- 【Linux】【Services】【Docker】网络
容器的网络模型: closed container: 仅有一个接口:loopback 不参与网络通信,仅适用于无须网络通信的应用场景,例如备份.程序调试等: --net none bridged co ...
- 【Linux】【Services】【Docker】应用
1. Docker应用: 镜像:包含了启动Docker容器所需要的文件系统层级及其内容:基于UnionFS采用分层结构实现: bootfs,rootfs registry:保存docker镜像及镜像层 ...
- 【Linux】【Services】【Docker】基础理论
1. 名称空间:NameSpace 内核级别,环境隔离: 1.1. 名称空间的历史 PID NameSpace:Linux 2.6.24 ,PID隔离 Network NameSpace:Linux ...
- Micro Frontends & microservices
Micro Frontends & microservices https://micro-frontends.org/ https://github.com/neuland/micro-fr ...
- Docker入门(四):服务(Services)
这个<Docker入门系列>文档,是根据Docker官网(https://docs.docker.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指 ...
随机推荐
- idea查看接口及类的关系继承(UML)图
选中接口或类 显示结果: 如果需要添加其他的接口或类:点击右键 添加需要的接口或类: 显示结果:
- idea安装阿里云插件和sonar插件
重启idea
- __init__调用之二
class Bar: def __init__(self,name,age): self.suibian = name #self后的名字是啥,对象就可以调用啥,而不是 __init__ 后括号形参 ...
- mybatis执行流程
mybatis 简介 开源的持久层框架:代码简洁,写sql,性能还可以.容易掌握 执行图 文字说明 先创建核心配置文件(sqlMapConfig.xml) 再创建映射文件(可以有多个 ~ 通常有多少张 ...
- box-shadow 用法总结
一.基础知识 box-shadow 属性向框添加一个或多个阴影. 语法 box-shadow: offset-x offset-y blur spread color inset; box-shado ...
- composer 无法配置命令行写入配置文件问题
composer config repo.packagist composer https://packagist.phpcomposer.com 这条命令无法修改composer.json 添加中国 ...
- Redis--set类型操作命令
集合类型 set redis 的 Set 是 string 类型的无序集合,集合成员是唯一的,即集合中不能出现重复的数据 集合类型 set ——常用命令 sadd /smembers /sismemb ...
- PAT(B) 1083 是否存在相等的差(Java)统计
题目链接:1083 是否存在相等的差 (20 point(s)) 题目描述 给定 N 张卡片,正面分别写上 1.2.--.N,然后全部翻面,洗牌,在背面分别写上 1.2.--.N.将每张牌的正反两面数 ...
- WUSTOJ 1325: Distance(Java)坐标计算
题目链接:1325: Distance Description There is a battle field. It is a square with the side length 100 mil ...
- Linux 进程控制
分享知乎上看到的一句话,共勉: 学习周期分为学习,思考,实践,校正四个阶段,周期越短,学习效率越高. 前面讲的都是操作系统如何管理进程,接下来,看看用户如何进行进程控制. 1.进程创建 先介绍一下函数 ...