Inferensys

Glossary

ROS Service

A ROS Service is a synchronous, request-response communication mechanism in the Robot Operating System (ROS) where a client node sends a request to a server node and blocks until it receives a reply.
Developer building agentic RAG system, retrieval pipeline diagram on laptop, technical workspace with notes.
ROBOT OPERATING SYSTEM (ROS)

What is a ROS Service?

A core communication mechanism within the Robot Operating System (ROS) framework for synchronous, request-response interactions between nodes.

A ROS Service is a synchronous, request-response communication mechanism where a client node sends a request to a server node and blocks execution until it receives a reply. This pattern is defined by a .srv file, which specifies the exact data structure for both the request and response messages. Unlike the continuous, many-to-many flow of ROS Topics, a service provides a direct, one-to-one procedure call abstraction, making it ideal for on-demand operations like calculations, state queries, or triggering discrete actions.

Services are built on top of the same underlying transport layer as topics but implement a blocking client call. The server node advertises a service by name and type, and client nodes can then discover and call it. This mechanism is fundamental for implementing deterministic, transactional interactions in a robotic system, such as requesting a map conversion, querying sensor calibration, or initiating a specific diagnostic check. For long-running or interruptible tasks, the ROS Action interface is typically more appropriate.

COMMUNICATION PATTERN

Key Characteristics of ROS Services

ROS Services provide a synchronous, request-response communication mechanism, distinct from the asynchronous publish-subscribe model of ROS Topics. This section details their defining operational features.

01

Synchronous Request-Response

A ROS Service is a blocking, one-to-one communication pattern. A client node sends a request message to a server node and blocks its execution thread until it receives a reply. This is fundamentally different from the asynchronous, streaming nature of topics.

  • Blocking Call: The client's call() or call_async() (followed by spin_until_future_complete) function waits for the server's response.
  • Defined Interface: Each service has a single, strictly typed .srv file defining the structure of the request and response messages.
  • Use Case: Ideal for remote procedure calls (RPC), performing calculations, querying a database, or triggering a discrete, non-continuous action where an immediate result is required.
02

Service Definition (.srv File)

The communication contract for a service is defined in a .srv file. This file specifies the exact data types for the request and the response, separated by three dashes (---).

Example (AddTwoInts.srv):

code
int64 a
int64 b
---
int64 sum
  • Top Section (Request): Defines the message the client must send (a and b).
  • Bottom Section (Response): Defines the message the server will return (sum).
  • Strict Typing: Like ROS messages, .srv definitions use primitive types (e.g., int32, string, bool) or other message types, ensuring data integrity. The ROS build system generates language-specific code (e.g., C++/Python classes) from these files.
03

Server-Client Architecture

The service pattern enforces a clear server-client relationship, unlike the many-to-many topology of topics.

  • Service Server: A node that advertises a service by name (e.g., /add_two_ints). It registers a callback function that is executed each time a request is received. This function processes the request data and must return a response message.
  • Service Client: A node that creates a client for a specific service name. It populates a request message object and calls the service. There can be multiple clients for a single server.
  • Discovery: Using the underlying middleware (e.g., DDS in ROS 2), clients dynamically discover available servers. A client will fail if it attempts to call a service for which no server is currently advertising.
04

Comparison with Topics and Actions

ROS Services fill a specific niche between Topics and Actions in the ROS communication toolbox.

FeatureROS TopicROS ServiceROS Action
ModelPublish-Subscribe (async stream)Request-Response (sync call)Goal-Feedback-Result (async task)
Blocking?NoYes (client side)No (client can poll)
Data FlowOne-way, continuousTwo-way, single exchangeTwo-way, with intermittent feedback
Best ForSensor data, state updatesRPC, quick computationsLong-running, interruptible tasks (e.g., navigation)

Services are simpler than Actions but lack feedback and preemption capabilities, making them unsuitable for long-duration operations.

05

Common Use Cases & Examples

ROS Services are employed for discrete operations where a direct answer is needed.

  • Configuration & Calibration: A client calls a set_parameters service to configure a sensor node.
  • Triggering Operations: save_map, start_recording, or calibrate_imu.
  • Querying State: get_plan from a planner, get_transform from TF (though TF2 uses a more efficient system).
  • Simple Computations: A centralized calculate_inverse_kinematics service for a manipulator.

ROS 2 Python Example (Client):

python
from example_interfaces.srv import AddTwoInts
...
client = node.create_client(AddTwoInts, 'add_two_ints')
req = AddTwoInts.Request()
req.a = 5
req.b = 3
future = client.call_async(req)
rclpy.spin_until_future_complete(node, future)
response = future.result()
node.get_logger().info(f'Sum: {response.sum}') # Output: 'Sum: 8'
06

ROS 2 Quality of Service (QoS) for Services

In ROS 2, service communication benefits from configurable Quality of Service (QoS) policies, inherited from the underlying DDS layer. These are set when creating the server or client.

Key QoS profiles for services include:

  • Reliability: Typically set to RELIABLE (ensure request/response delivery) versus BEST_EFFORT.
  • History Depth: For the request queue on the server side.
  • Deadline: Optional duration within which the service call should complete.

These policies allow tuning service behavior for different network conditions, making ROS 2 services more robust and suitable for deterministic systems compared to ROS 1 services. The default QoS profile for services is generally reliable, matching the expectation of a guaranteed response.

SYNCHRONOUS COMMUNICATION

How ROS Services Work: Mechanism & Flow

A ROS Service provides a synchronous, request-response communication pattern, enabling deterministic, blocking interactions between nodes in a robotic system.

A ROS Service is a synchronous, request-response communication mechanism where a client node sends a request to a server node and blocks until it receives a reply. This pattern is ideal for remote procedure calls (RPCs) that require a deterministic, immediate answer, such as querying a sensor's status or performing a quick calculation. Unlike the continuous data stream of a ROS Topic, a service call is a discrete, one-time transaction.

The service flow begins when a client calls the service using a defined ROS Service Message type, which specifies the structure of both the request and response. The server, which has previously advertised the service, receives the request, executes its callback function to process it, and returns the response. This blocking call ensures the client's execution thread pauses, providing straightforward error handling and guaranteed sequencing for critical operations within the robotic software architecture.

SYNCHRONOUS COMMUNICATION PATTERNS

Common Use Cases for ROS Services

ROS Services provide a synchronous, request-response mechanism ideal for operations that require a direct, blocking answer. This section details the primary scenarios where this communication pattern is essential.

01

Configuration and Parameter Retrieval

Services are the standard mechanism for a node to dynamically request configuration data from a central parameter server or another configuration node. This is a core alternative to the parameter server's asynchronous event system.

  • Example: A navigation node calls a /get_map service to request the current occupancy grid from a map server before planning a path.
  • Key Benefit: The client node blocks until it receives the necessary configuration, ensuring it does not proceed with stale or missing data.
02

On-Demand Computation and Queries

Services are used to trigger a specific, often resource-intensive, computation and return a single result. This is preferred over a continuous topic stream when data is only needed occasionally.

  • Example: A /detect_object service where a client sends an image and blocks until the server returns the bounding boxes and classifications.
  • Example: A /calculate_inverse_kinematics service for a robotic arm, where the client provides a desired end-effector pose and receives the corresponding joint angles.
03

State Machine Transitions and Control Commands

Services provide a clean interface for discrete, one-shot commands that change a system's operational mode or state. The client receives immediate confirmation of success or failure.

  • Example: A /start_recording or /calibrate_sensor service for a data logging node.
  • Example: In ROS 2 Lifecycle Nodes, the ~/change_state service is used to transition a node between its managed states (e.g., Unconfigured → Inactive → Active).
04

Database and Lookup Operations

Services are ideal for querying a static or slowly changing dataset, such as a semantic map, a knowledge base, or a task database. The request contains the query parameters, and the response contains the matched records.

  • Example: A /query_location service that returns the coordinates of a named landmark (e.g., 'charging_station_1') from a semantic map.
  • Key Benefit: The synchronous nature ensures the client has the lookup result before deciding its next action.
05

Error Handling and Status Checks

Services can be used for health checks and diagnostic queries where a managing node periodically requests status from subordinate nodes. The response contains detailed health information or error codes.

  • Example: A /get_diagnostics service that returns the internal status, error logs, and self-test results of a motor controller.
  • Contrast with Topics: While diagnostics can be published on a topic, a service allows for on-demand, guaranteed delivery of the latest status snapshot.
06

Synchronization in Multi-Node Sequences

In complex workflows, services can act as synchronization points or barriers. A coordinating node can call a series of services on different nodes in sequence, ensuring each step completes before the next begins.

  • Example: A pick_and_place sequence: 1) Call /plan_grasp service on the perception node. 2) Call /execute_trajectory service on the arm controller with the result. 3) Call /update_inventory service on the database node.
  • Consideration: For long-running tasks with intermediate feedback, the ROS Action protocol is more appropriate.
COMMUNICATION PATTERN COMPARISON

ROS Service vs. Topic vs. Action

A comparison of the three primary communication mechanisms in the Robot Operating System (ROS), detailing their core characteristics, use cases, and technical behaviors.

FeatureROS TopicROS ServiceROS Action

Communication Model

Asynchronous Publish/Subscribe

Synchronous Request/Response

Asynchronous Goal/Feedback/Result

Blocking Behavior

Non-blocking

Client blocks until reply

Client non-blocking; can monitor/cancel

Connection Pattern

Many-to-many

One-to-one (per request)

One-to-one (per goal)

Data Flow

Unidirectional stream

Bidirectional, single exchange

Bidirectional, with intermediate feedback

Primary Use Case

Continuous sensor data, state broadcasts

On-demand computation, configuration queries

Long-running, interruptible tasks (e.g., navigation)

Latency Profile

Low, best-effort (configurable via QoS)

Medium, bounded by server processing time

High, task duration plus feedback overhead

Built On

Native DDS publications/subscriptions

Two paired DDS request/reply topics

Five coordinated DDS topics (Goal, Cancel, Status, Feedback, Result)

State Management

Stateless

Stateless (per call)

Stateful (goal lifecycle: PENDING, EXECUTING, etc.)

ROS SERVICE

Frequently Asked Questions

A ROS Service is a synchronous, request-response communication mechanism where a client node sends a request to a server node and blocks until it receives a reply. This FAQ addresses common technical questions about its operation, design, and use cases.

A ROS Service is a synchronous, request-response communication mechanism where a client node sends a request to a server node and blocks until it receives a reply. It operates as a remote procedure call (RPC) within the ROS graph. A service is defined by a pair of ROS Message types: one for the request and one for the response. A server node advertises a service by name and provides a callback function to handle incoming requests. A client node creates a service client, calls the service with a request message, and waits synchronously for the server to process the request and return a response message. This blocking nature makes services ideal for transactional operations, such as performing a calculation, looking up a value, or triggering a discrete, non-continuous action.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.