Skip to main content

What is DDP?

DDP (Distributed Data Protocol) is Meteor’s protocol for syncing data between client and server. It’s a simple, REST-like protocol for fetching structured data from a server, and receiving live updates when that data changes.
DDP is to realtime web apps what REST is to traditional web apps - a standardized way to send data over the network.

Package Structure

DDP is implemented across three core packages:

ddp

Main package that combines client and server

ddp-client

Client-side DDP implementation

ddp-server

Server-side DDP implementation (server-only)

Package Dependencies

From packages/ddp/package.js:

ddp-common Package

Shared code between client and server:
packages/ddp-common/package.js

Core Concepts

The Connection

A DDP connection is established via WebSocket:

Connection Implementation

From packages/ddp-client/common/livedata_connection.js:

DDP Messages

DDP uses JSON messages over WebSocket. Here are the core message types:

Connection Messages

Client initiates connection:
Server responds:
Keep connection alive:
With IDs:

Method Messages

Client calls method:
Server responds with result:
Or with error:
Server signals method side effects are complete:
This means all database changes from method “1” have been sent to the client.

Subscription Messages

Client subscribes:
Server sends initial data via added messages, then:
Client unsubscribes:
Server confirms:

Data Messages

Server tells client about new document:
Server tells client about changes:
With removed fields:
Server tells client document was removed:

Publications and Subscriptions

Server: Publications

Define what data clients can subscribe to:

Client: Subscriptions

Subscribe to published data:

React Integration

Methods (RPC)

Server: Define Methods

Client: Call Methods

Latency Compensation

DDP implements optimistic UI through latency compensation:

Stub Functions

Define client-side simulation:

Connection Management

Connection States

Manual Connection Control

Advanced Features

Multiple DDP Connections

DDP Rate Limiting

Custom DDP Messages

Best Practices

Never trust the client - always validate on server:
Use check package:
Only subscribe to data you need:

Next: Full-Stack Development

Learn how to build complete full-stack applications with Meteor