Stub Generation in Distributed System

Last Updated : 26 Mar, 2026

A stub is a piece of intermediary code that translates parameters and results between the client and server during a Remote Procedure Call.

  • Converts procedure parameters into a transferable format
  • Resolves differences between separate client and server address spaces
  • Prevents invalid memory references across machines

Role of Client and Server Stubs

rpc_execution_steps4
Client and Server Stubs

1. Client Stub

This acts as a local proxy for the remote procedure on the client machine.

  • Marshals function parameters into a message
  • Sends request to the RPC runtime
  • Receives response from the server
  • Unmarshals returned results
  • Delivers final output to the client application

2. Server Stub

This manages the reception and conversion of client requests on the server machine.

  • Unmarshals incoming request parameters
  • Invokes the actual server procedure
  • Marshals execution results into a response message
  • Sends response back to the client through RPC runtime

Stub Generation

It is the process of creating client and server stub code that handles parameter translation and communication in RPC systems. Stubs can be generated in two ways:

1. Manual Stub Generation

The programmer writes stub code using provided translation functions.

  • Developer creates custom stubs for client and server
  • Uses predefined translation utilities
  • Allows flexible handling of argument types
  • Suitable for simple or controlled environments
  • Increases development effort and maintenance complexity

2. Automatic Stub Generation

Stubs are created automatically using an Interface Definition Language (IDL).

  • Client and server interfaces are defined in IDL
  • IDL specifies input, output, or input–output parameters
  • Only required parameters are transmitted between systems
  • An IDL compiler generates client and server stubs
  • Most commonly used method in modern RPC systems

Interface Definition Language (IDL)

This is used to formally define interfaces for distributed applications.

  • Defines procedure names and parameter types
  • Supports input, output, and bidirectional arguments
  • IDL compiler generates marshalling and unmarshalling code
  • Produces header files shared by client and server
  • Enables communication between programs written in different languages

1. Import an Interface:

A client program that uses procedures defined in an interface is said to import the interface.

  • Calls remote procedures defined in IDL
  • Links with generated client stub code

2.Export an Interface:

A server program that implements procedures defined in an interface is said to export the interface.

  • Provides actual implementation of procedures
  • Links with generated server stub code
Comment

Explore