Coder Social home page Coder Social logo

go-grpc's Introduction

JSON vs Protocal Buffer

Parsing JSON is CPU intensive and JSON takes more memory
Parsig PRotocal Buffers(Binary Format) is les CPU intensive because it's closer to machine represents data
Protocol Buffers allows faster and more efficient communication

gRPC leverages HTTP/2 as a backbone of communications/uses only HTTP/2
HTTP/2 is comparatively very fast than HTTP/1.1
Eg: https://imagekit.io/demo/http2-vs-http1

gRPC servers are asynchronous by default
Types:
- Unary
- Server Streaming
- Client Streaming
- Bi Directional Streaming

HTTP/2 vs HTTP/1.1

HTTP/2 is the newer standard for internet communications that addresses common pitfall of HTTP/1.1
on modern webpages

HTTP/1.1:
- Released in 1997
- Opens a new TCP connection to server at each request
- Does not compress the Headers(which are plain text - heavy size)
- Only works with Request/Response mechanism

HTTP/2:
- Released in 2015
- Developed by google under the name SPDY
- Supports multiplexing that means client and server can push messages in parallel over same TCP connection
- Reduces latency
- Server can push miltiple messages with single request from client / saves round trips
- Supports compressed Headers
- HTTP/2 is binary -> an extremely great match for Protocol Buffers
- Secure -> SSL is not required but recommended by default)

Installations Required:

Proctoc Setup:
Mac: brew install protobuf
Download the windows archive: https://github.com/google/protobuf/releases

go gRPC: go get -u google.golang.org/grpc
go Protocol Buffer: go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
Mac: Add them to bash_profile
    - vim ~/.bash_profile
    - Add: 
        export GO_PATH=~/go
        export PATH=$PATH:/$GO_PATH/bin
    - source ~/.bash_profile

if there are issues with Protocol Buffers:
- Download the protobuf-2.4.1 from https://protobuf.googlecode.com/files/protobuf-2.4.1.tar.gz
- Extract the tar.gz file.
- $cd ~/Downloads/protobuf-2.4.1
- $./configure
- $make
- $make check
- $sudo make install
- $which protoc
- $protoc --version

Running the samples:

Greeting:
- To generate the greet.pb.go: "protoc greet/greetpb/greet.proto --go_out=plugins=grpc:."
- Running the server: go run greet/greet_server/server.go
- Running the client: go run greet/greet_client/client.go

Calculator:
- To genrate the calculator.pb.go: "protoc calculator/calculatorpb/calculator.proto --go_out=plugins=grpc:."
- Running the server: go run calculator/calculator_server/server.go
- Running the client: go run calculator/calculator_client/client.go

go-grpc's People

Watchers

James Cloos avatar Mayank Gupta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.