Giter Club home page Giter Club logo

grpc-tutorial's Introduction

  1. Unary RPC diawali dengan client mengirimkan single request ke server dan menunggu response dari server
    Scenario: simple client-server interaction, client meminta request untuk read suatu data, kemudian server meresponse dengan data yang diinginkan.
    Server Streaming RPC diawali dengan client mengirimkan single request ke server, kemudian server merespons dengan mengirimkan a stream f message.
    Scenario: client request real-time weather information, lalu server mengirimkan informasi cuaca secara real-time dan continu kepada client.
    Bi-directional streaming membolehkan client dan server untuk mengirimkan a stream of message secara asynchronously.
    Scenario: client dan server terlibat komunikasi secara simultaneously, online, dan asynchronously pada suatu chat application. Scenario lainnya yaitu bermain game secara online dimana client dan server aktif mengirimkan data satu sama lain.
  2. Authentication: gunakan client-side certificates atau API keys untuk mengautentikasi clienbts sebelum membolehkan akses ke service.
    Authorication: define dan enforce acess control policies untuk mengetahui yang mana client atau user yang mempunyai permission untuk mengakses spesific resources.
    Data encryption: Gunakan cryptographic algorithm yang kuat dan gunakan juga key management practices untuk encrypt sensitive data saat sampai maupun saat transit.
  3. Memastikan thread safety dan mencegah data races saat mengakses shared resources atau state di antara multiple stream memerlukan design yang teliti dan synchronization.
    Memanage memory allocation dan deallocation akan menjadi complex khususnya saat menghandle banyak concurrent streams.
    Rust's ownership and borrowing system can help prevent memory leaks and resource exhaustion, but improper management may lead to performance degradation or system instability.
  4. Advantages: Tokio adalah asynchronous runtime yang sangat popular sehingga mudah digunakan dengan component dan library lain di Tokio, memperbolehkan asynchronous communication, mudah mengontrol concurrency secara effectively berkat mpsc::Receiver.
    Disadvantages: Cukup sulit dalam mencegah memory leaks dan undefined behavior, terdapat high learning curve sehingga butuh waktu dan tenaga yang ekstra untuk mempelajarinya.
    • Tulis gRPC service interface di file .proto yang terpisah untuk menjaga service definition tetapi clean dan modular.
    • Gunakaqn build system seperti `prost` atau `grpc-rs` untuk menggenerate Rust code dari file .proto supaya code tersebut digenerasi di module/folder terpisah dari application code.
    • Implementasi setiap gRPC service di module/file nya tersendiri agar menjadi single responsibility principle (SRP).
  5. Menyertakan error handling ketika payment gagal, menambahkan validasi dan verifikasi.
    • gRPC bergantung pada Protocol Buffers (protobuf) untuk mendefinisikan service interface dan data serialization. Hal ini menghasilkan clear and concise service contract, yang mana merincikan methods, parameters, dan data types exchanged di antara client dan server.
    • Penggunaan protobuf memperkenankan language-agnostic service definitions, memperbolehkan adanya interoperability di antara beberapa programming language dan paltforms.
  6. Advantages: Memperkenankan multiple request dan response untuk di multiplexed dalam single TCP connection, mendukung header compression untuk mencegah overhead saat mengirimkan HTTP headers, support server push yaitu push additional resources ke clients tanpa menunggu untuk explicit request.
    Disadvantages: lebih complex, multiplexing dan header compression memakan server-side resources lebih banyak.
    • request-response model menggunakan unary streaming.
    • real-time request-response model pada REST API biasanya menggunakan teknik polling atau long polling sehingga lebih tinggi latency dan low-throughput.
    • karena tanpa frequest polling, gRPC bidirectional streaming menghasilkanb network overhead yang lebih sedikit dan responsiveness yang lebih.
    • Protobuf memerlukan sebuah predefined schema (.proto file) yang mendefinisikan struktur dari data exchanged antara client dan server. Schema ini dikompilasi ke language-spesific code, mengenforce strong typing dan validasi data saat compile time.
    • gRPC menyediakan tooling untuk menggenerate client dan server code dari protobuf schema definitions, menbgautomasi process dari message serialization, deserialization, dan RPC invocation.

grpc-tutorial's People

Contributors

dhekmass12 avatar

Watchers

 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.