Split a robot application into services
Separate model loading, API work, and presentation without confusing startup with readiness.
Requirements and learning goals
Before you start
- The hello-wendy Node project from the first three lessons
- Basic HTTP and container knowledge
You will be able to
- Declare service dependencies and per-service resources
- Test partial failure and recovery
The project brief below assumes the listed prerequisites and gives you a task and checks to perform. Need a guided first project?
A service is a separately running part of an application, such as an server or dashboard. Splitting them lets you update the dashboard without rebuilding the model server. It also introduces network failures and startup dependencies, so begin with one service unless separation solves a real problem. Each service still needs a working build context and observable health.
The local VLM example separates the model backend from the camera UI, so UI iteration does not require redeploying the model service.
Existing docker-compose.yml projects are supported too, with a companion wendy.json for device settings. Keep per-service Dockerfiles; neither nor rewriting the stack into a services map is required. The example below shows the latter option.
Declare a small stack
Each service's context is a directory path relative to the project root containing wendy.json. For example, "context": "api" uses ./api/ as that service's build context. It is not an image name or a URL.
Keep the original hello-wendy directory as your working single-service example. Stop its attached run before continuing. From its parent directory, make a separate stack:
mkdir -p hello-stack/api hello-stack/web
cp -R hello-wendy/src hello-wendy/package.json hello-wendy/tsconfig.json hello-stack/api/
cp hello-wendy/Dockerfile hello-stack/api/Dockerfile
cd hello-stackThis exercise uses Dockerfiles for both services. In api/src/index.ts, set const port = 3000;. Keep the routes and persistence counter. If you generated package-lock.json, copy it into api/ too.
Save this as web/server.mjs. The browser calls the web service; the web service calls the API on the device:
import { createServer } from "node:http";
const page = `<!doctype html><html lang="en"><meta charset="utf-8">
<title>Hello stack</title><h1>Hello stack</h1><pre id="result">Waiting for API</pre>
<script>
async function poll() {
try {
const response = await fetch('/api');
document.querySelector('#result').textContent = await response.text();
} catch { document.querySelector('#result').textContent = 'Web service unavailable'; }
setTimeout(poll, 1000);
}
poll();
</script></html>`;
createServer(async (request, response) => {
if (request.url === "/api") {
try {
const upstream = await fetch("http://127.0.0.1:3000/", {
signal: AbortSignal.timeout(2000),
});
const body = await upstream.text();
response.writeHead(upstream.status, { "Content-Type": "application/json", "Cache-Control": "no-store" });
response.end(body);
} catch {
response.writeHead(503, { "Content-Type": "text/plain", "Cache-Control": "no-store" });
response.end("Waiting for API");
}
} else {
response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
response.end(page);
}
}).listen(8081, "0.0.0.0");Save web/Dockerfile:
FROM node:22-slim
WORKDIR /app
COPY server.mjs .
CMD ["node", "server.mjs"]Each Dockerfile's COPY paths are relative to its own directory. The web service uses no npm packages.
Create hello-stack/wendy.json:
{
"appId": "com.example.learn-stack",
"platform": "linux",
"entitlements": [
{ "type": "network", "mode": "host" },
{ "type": "persist", "name": "learn-state", "path": "/data" }
],
"services": {
"api": {
"context": "api",
"readiness": { "tcpSocket": { "port": 3000 }, "timeoutSeconds": 30 }
},
"web": {
"context": "web",
"dependsOn": ["api"],
"readiness": {
"tcpSocket": { "port": 8081 },
"timeoutSeconds": 30
}
}
}
}From hello-stack/, deploy to the same device:
wendy run --build-type dockerOpen http://DEVICE_ADDRESS:8081, replacing the address with your target's reachable LAN address. Expect the JSON message from your existing API. This new app identity has its own persistent state, so its startup counter begins independently of hello-wendy.
Host networking lets the web service reach the API at device loopback port 3000. The browser uses port 8081 on the device, not its own localhost. Keep both device ports free.
Test partial readiness
In api/src/index.ts, replace the final app.listen(...) block with:
setTimeout(() => {
app.listen(port, () => console.log(`API ready on ${port}`));
}, 15000);Stop the attached run, redeploy, and open the dashboard during startup. Expect "Waiting for API", then the original JSON without refreshing once the API is ready. Remove the delay afterward and redeploy.
dependsOn controls creation order, not dependency health. A readiness probe gates its service's post-start behavior. A TCP connection also does not prove a model has loaded or a robot has fresh observations.
Detached runs skip the CLI readiness wait. After --detach, check every service and a request that crosses the complete stack.
Stop the attached run with Ctrl+C when finished. For the following recovery lesson you can return to hello-wendy; retain this stack as an optional extension.
Source: Multi-service configuration and readiness semantics.
Before you move on
Can you do each of these?
- Declare service dependencies and per-service resources
- Test partial failure and recovery
0 of 2 checkpoints solved. Try checkpoint 1