ROS2 Services
662 words · 4 min read · 3 sources
A ROS 2 service is a short question one piece of a robot's software asks another and waits for a single answer to — "save the map", "spawn a turtle", "what are your settings?" — rather than a continuous stream of data.
A ROS 2 service is a call-and-response exchange between nodes. One node (the service client) sends a request; another node (the service server) does a small amount of work and sends back a response. Nothing is sent until a client asks, and the client generally waits for the answer.
🤯 ROS 2 lets any number of nodes call the same service, but only one node may answer it. If two servers advertise the same service name, the documentation says outright that which one receives a client's request is undefined.
🎯 Quick challenge
A node needs to ask another node to clear the screen and tell it whether that worked. The job finishes in a fraction of a second. Which ROS 2 communication pattern fits?
A ROS 2 service is a short question one piece of a robot's software asks another and waits for a single answer to. In the words of the ROS 2 documentation, "a service refers to a remote procedure call" — a node asks another node to do a computation and return a result.
Services are based on a call-and-response model, unlike the publisher-subscriber model of topics. A topic is a tap left running: it streams data whether or not anyone is listening. A service is a doorbell: nothing happens until a client presses it, and the client expects somebody to answer.
When do you reach for a service?
ROS 2 gives nodes three ways to talk. Picking the wrong one is the single most common beginner mistake in the framework, and the distinction is simple once you see it side by side.
| Reply? | Progress updates? | Reach for it when | |
|---|---|---|---|
| Topic | None | — | Data flows continuously and listeners come and go: sensor readings, velocity commands |
| Service | Exactly one, and the caller waits | No | A one-off command or question that finishes fast: save the map, switch mode, read settings |
| Action | One result at the end | Yes, a steady stream, and it can be cancelled | A job that runs for seconds or minutes: navigate somewhere, grasp an object |
Two rules follow from that table, and both are in the official docs. Services are expected to return quickly, because the client is generally waiting on the result — so a long computation should be an action, not a service. And you generally should not use a service for continuous calls; a topic (or an action) fits better.
Request and response
A service has a name and a service type. Service types look like topic types with two halves: one message for the request and another for the response, separated by ---. Here is turtlesim's Spawn service, as ros2 interface show prints it:
float32 x
float32 y
float32 theta
string name # Optional. A unique name will be created and returned if this is empty
---
string name
Everything above the line is what you send; everything below is what comes back. You can call it from a terminal without writing any code:
$ ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}"
Some services carry no data in either direction. Turtlesim's /clear has the type std_srvs/srv/Empty, whose whole definition is a single --- — you are sending a pure command and getting a bare acknowledgement.
One server, many callers
A service has two sides: the service server, which accepts the request and does the work, and the service client, which asks. There can be arbitrary numbers of clients on the same service name, but there should only ever be one server — with two servers on one name, which one gets a request is undefined.
Where you will see services on a real robot
Nearly every node in ROS 2 ships with six built-in services with parameters in their names — get_parameters, set_parameters, list_parameters and friends. The whole parameter system is built on top of them, which is why a bare turtlesim node already advertises a dozen services before you add any of your own.
Common questions
How do I find out what services a robot offers?
ros2 service list prints every active service, ros2 service list -t adds each one's type in brackets, and ros2 service info <name> shows the type plus how many clients and servers it has.
Does calling a service freeze my program?
The client waits for a response, so a naive blocking call will stall. That is exactly why the docs insist services return quickly: anything slow belongs in an action, which reports progress and can be cancelled.
Can I watch the traffic on a service the way I can echo a topic?
Yes, with ros2 service echo, but not out of the box. It relies on service introspection, which is disabled by default — each client and server has to call configure_introspection first.
Next step: ROS 2 Actions — what to use when the job is too long for a service to wait on.
Next: the course path
Five free courses, from zero to your own robot design
Short videos with a quiz after each one, a final activity and a certificate per course.
See the course path →Plain English. Free. Unsubscribe in one click.
Keep going
ROS2
Robot Operating System 2 — the DDS-based middleware that runs nearly every modern research and commercial robo…
ConceptROS2 Nodes
A ROS2 node is a single-process unit of computation that publishes and subscribes to topics, services, and act…
ConceptROS2 Topics
ROS2 topics are typed, asynchronous message buses that let robot nodes publish and subscribe data — like senso…
Last updated · 2026-11-08
Spotted something off? Report an error →