Engineering
January 8, 2025

Real-time robot control with gRPC and WebRTC

Joyce Lin
Head of Developer Relations

Originally published on HackerNoon

Robots work in all kinds of places with varying network conditions, from stable ethernet to inconsistent cellular or satellite connections. Learn how you can use gRPC and WebRTC for robots and other smart machines to communicate more reliably.

Operate a rover using the Viam gRPC API in Postman
Operate a rover using the Viam gRPC API in Postman

Why use gRPC AND WebRTC for controlling robots?

I recently started a new job at Viam, and was curious to learn more about their system architecture. Many robotics systems are composed of low-power and low-bandwidth devices, or operate in poor network conditions. Viam is an open-source robotics software platform that was designed specifically to help robots and other smart machines communicate more reliably.

It uses gRPC for fast, structured client-server communication and WebRTC for direct, peer-to-peer communication between machines. Let’s explore the benefits of using gRPC and WebRTC in more detail.

Benefits of using gRPC and Protobuf in robotics

There’s a number of reasons to use gRPC for robotics, such as for improved developer productivity and developer experience. However, the most compelling reason is that it is optimized for speed, perhaps up to 7–10x faster than REST APIs over HTTP, with lightweight Protobuf messaging.

Performance and efficiency

  • Encoding: Protobuf offers efficient binary encoding, ideal for machines with low power, memory, compute, or bandwidth constraints compared to JSON-RPC.
  • Transport: Along with the default transport of HTTP/2, gRPC supports alternative transports like HTTP/1.1 with gRPC-Web and WebRTC. This provides a consistent interface with the flexibility of underlying transport technology, especially with streaming.

Components and services in the Viam API are represented as language-agnostic Protocol Buffer (protobuf) services, and gRPC is responsible for the transport and communication of protobuf messages when calling protobuf methods.

Components and services in the Viam API represented as protobuf
Components and services in the Viam API represented as protobuf

Specifically, Viam uses gRPC for high-level interactions between machine parts and SDK-based applications, enabling structured, low-latency data exchange and control commands. This is an efficient way to coordinate work to be done, such as retrieving point clouds from cameras, analyzing data for object segmentation, and instructing robotic arms to perform tasks based on computed poses.

Protobuf minimizes the size of the transmitted data, saving network bandwidth during transmission.

Benefits of using WebRTC in robotics

There’s a number of reasons to use WebRTC in robotics, such as for security and cross-platform compatibility. However, the most compelling reason is that it uses a direct connection.

Peer-to-peer communication

  • Direct: WebRTC facilitates direct connections between devices, reducing reliance on central servers and minimizing the traversal route of data.
  • Network adaptability: Adjusts media quality based on network conditions for smooth performance, such as for video streaming.

Viam relies on WebRTC for peer-to-peer communication, allowing direct video and data streams between machine parts and the Viam SDK. This means once the initial connection is established, your data doesn’t need to take the long way going through a central server on its way to talking to another machine. This setup optimizes real-time responsiveness and operational efficiency especially with complex machine configurations.

WebRTC enables direct peer-to-peer communication, avoiding intermediate servers that could introduce delays or points of failure.

How Viam uses gRPC and WebRTC to enable peer-to-peer robot communication

Let’s see how this works in the example of an arcade claw game composed of two machine parts: a camera and an arm.

Viam controls components of a robot in an arcade claw game
Viam controls components of a robot in an arcade claw game

The Viam app (app.viam.com) listens for connection requests, sends connection details, and then lets the two peers communicate directly. The initial connections are facilitated over gRPC.

iam uses gRPC to initialize connections and WebRTC for peer-to-peer communication in this robot claw game
Viam uses gRPC to initialize connections and WebRTC for peer-to-peer communication in this robot claw game

Once connected, the machine parts communicate over WebRTC, allowing all interactions between SDKs and machines to happen over WebRTC using gRPC method calls. In other words, the gRPC schema decides what the data looks like and how it’s packaged, while WebRTC handles the actual delivery of that data from one place to another.

Get started with robotics using Viam

While you could build out a similar infrastructure on your own, Viam provides this capability with off-the-shelf robotics software. The on-machine functionality is open-source and free to operate. If you eventually start managing a fleet, it’s usage-based billing for cloud services and data storage.

The Viam web app and SDKs were designed to help you work with your machines. However, if you want to explore what’s happening behind-the-scenes, check out the Viam APIs public workspace in Postman for step-by-step instructions on working with the underlying Viam gRPC APIs, including:

  • Authorizing gRPC API calls
  • Invoking methods to control hardware components
  • Invoking methods to manage software services
The Viam gRPC API collection for reference
The Viam gRPC API collection for reference

You may not have a robotic arm at your disposal, but you can try this out with a more affordable machine, like a rover, such as Yahboom or SCUTTLE. Viam also designed an open-source rover to help folks learn about robotics.

Use gRPC and WebRTC to operate a rover

To get started, fork the Spin a Viam rover collection to your own workspace by clicking the Run in Postman button below.

Fork the gRPC collection to your own workspace by clicking the Run in Postman button
Fork the gRPC collection to your own workspace by clicking the Run in Postman button

And follow along with these resources:

Technical review by: Nick Hehr

twitter iconfacebook iconlinkedin iconreddit icon

Find us at our next event

May 14, 2025
,

AuthCon

In Person
New York
Don't let your toaster order unauthorized parts! The adoption of devices that monitor and automate our world continues to grow at a rapid pace, including mobile robots, smart appliances, cameras & sensors at the edge.
Register now
May 15, 2025
,
6:30-9:00PM

Fireside Chat & Networking Reception

In Person
New York
​Join us for an intimate evening with Viam and Joyful Health. Hear directly from Viam Founder and CEO, Eliot Horowitz, on his entrepreneurial journey, gain valuable insights into the future of technology and AI, network with industry professionals, and meet hiring managers at Viam and Joyful Health.
Join us
Jun 4, 2025
,
5:00PM-8:00PM

NY Robotics - ROS Meetup w/ OSRA and Viam

In Person
New York
Stop by the Viam office during NY tech week to learn how Viam complements ROS with cloud-ready architectures with senior developer advocate, Nick Hehr.
Check it out
Jun 12, 2025
Jun 16, 2025
,

JS Nation

In Person
Amsterdam
WebRTC is most often associated with building video and text chat into browsers but this peer-to-peer technology can also be used to monitor and control machines from anywhere in the world! Join Nick Hehr to learn about industrial arms, DIY rovers, and dashboards of data in real time.
Register Now
Jun 23, 2025
Jun 25, 2025
,

Open Source Summit North America 2025

In Person
Denver, CO
Edge-based computer vision gives us real-time insights, but getting that data where it needs to go without high bandwidth, lag, or hardware strain is a big challenge. Learn how to build a fast, event-driven vision pipeline.
Learn More