dynamo/examples/custom_backend/hello_world
Tzu-Ling Kan 0ce3461a9e
feat: Add runtime.endpoint() method to eliminate namespace chaining (#6386)
Signed-off-by: tzulingk@nvidia.com <tzulingk@nvidia.com>
2026-02-19 16:02:37 -05:00
..
deploy feat: normalize dynamo namespace computation (#5231) 2026-01-12 19:09:43 +00:00
README.md fix: consolidate dyn_discovery_backend and dyn_kv_store (#6167) 2026-02-13 19:07:11 +00:00
client.py feat: Add runtime.endpoint() method to eliminate namespace chaining (#6386) 2026-02-19 16:02:37 -05:00
hello_world.py feat: Add runtime.endpoint() method to eliminate namespace chaining (#6386) 2026-02-19 16:02:37 -05:00

README.md

Hello World Example

This is the simplest Dynamo example demonstrating a basic service using Dynamo's distributed runtime. It showcases the fundamental concepts of creating endpoints and workers in the Dynamo runtime system.

Architecture

Client (dynamo_worker)
      │
      ▼
┌─────────────┐
│   Backend   │  Dynamo endpoint (/generate)
└─────────────┘

Components

  • Backend: A Dynamo service with an endpoint that receives text input and streams back greetings for each comma-separated word
  • Client: A Dynamo worker that connects to and sends requests to the backend service, then prints out the response

Implementation Details

The example demonstrates:

  • Endpoint Definition: Using the @dynamo_endpoint decorator to create streaming endpoints
  • Worker Setup: Using the @dynamo_worker() decorator to create distributed runtime workers
  • Service Creation: Creating services and endpoints using the distributed runtime API
  • Streaming Responses: Yielding data for real-time streaming
  • Client Integration: Connecting to services and processing streams
  • Logging: Basic logging configuration with configure_dynamo_logging

Getting Started

Prerequisites

Dynamo must be installed. No external services are required for local development—the example uses file-based KV storage by default.

Running the Example

First, start the backend service:

cd examples/custom_backend/hello_world
DYN_DISCOVERY_BACKEND=file python hello_world.py

Second, in a separate terminal, run the client:

cd examples/custom_backend/hello_world
DYN_DISCOVERY_BACKEND=file python client.py

Note: Setting DYN_DISCOVERY_BACKEND=file uses file-based discovery instead of etcd. Both the backend and client must use the same discovery backend to discover each other.

The client will connect to the backend service and print the streaming results.

Expected Output

When running the client, you should see streaming output like:

Hello world!
Hello sun!
Hello moon!
Hello star!

Code Structure

Backend Service (hello_world.py)

  • content_generator: A dynamo endpoint that processes text input and yields greetings
  • worker: A dynamo worker that sets up the service, creates the endpoint, and serves it

Client (client.py)

  • worker: A dynamo worker that connects to the backend service and processes the streaming response

Deployment to Kubernetes

Note that this a very simple degenerate example which does not demonstrate the standard Dynamo FrontEnd-Backend deployment. The hello-world client is not a web server, it is a one-off function which sends the predefined text "world,sun,moon,star" to the backend. The example is meant to show the HelloWorldWorker. As such you will only see the HelloWorldWorker pod in deployment. The client will run and exit and the pod will not be operational.

Follow the Quickstart Guide to install Dynamo Kubernetes Platform. Then deploy to kubernetes using

export NAMESPACE=<your-namespace>
cd dynamo
kubectl apply -f examples/custom_backend/hello_world/deploy/hello_world.yaml -n ${NAMESPACE}

to delete your deployment:

kubectl delete dynamographdeployment hello-world -n ${NAMESPACE}