Skip to main content

Appendix A — Lab Setup

Goal. Get a working backend lab running in minutes so you can do every chapter's exercise. Here we use Docker as a tool — copy-paste and go. How containers actually work is derived from first principles in Ch 36; docker compose is explained there too. For now, treat it as "one command brings up four databases."

Prerequisites​

ToolWhyCheck
Node.js LTS (≥20) + a version manager (nvm/fnm)The book's primary lab is Node/TypeScriptnode --version
Docker Engine / Docker Desktop + Compose v2Runs Postgres, MongoDB, Redis, Kafka locallydocker --version && docker compose version
GitVersion control; the Pulsely project is trackedgit --version
psql, mongosh, redis-cli (optional CLIs)Poke the datastores directlyeach --version

You do not need to install Postgres/Mongo/Redis/Kafka on your machine — Compose runs them in containers and throws them away when you're done.

The one-command lab​

Create lab/docker-compose.yml:

# The Pulsely lab: Postgres, MongoDB, Redis, Kafka — plus a UI for each.
# Local-only credentials; never reuse these anywhere real.
name: pulsely-lab

services:
postgres:
image: postgres:16
environment:
POSTGRES_USER: pulsely
POSTGRES_PASSWORD: devpassword
POSTGRES_DB: pulsely
ports: ["5432:5432"]
volumes: ["pgdata:/var/lib/postgresql/data"]
healthcheck:
test: ["CMD-SHELL", "pg_isready -U pulsely"]
interval: 5s
timeout: 3s
retries: 10

mongo:
image: mongo:7
environment:
MONGO_INITDB_ROOT_USERNAME: pulsely
MONGO_INITDB_ROOT_PASSWORD: devpassword
ports: ["27017:27017"]
volumes: ["mongodata:/data/db"]
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 5s
timeout: 3s
retries: 10

redis:
image: redis:7
command: ["redis-server", "--appendonly", "yes"] # AOF persistence (Ch 21)
ports: ["6379:6379"]
volumes: ["redisdata:/data"]
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10

# Kafka in KRaft mode (no ZooKeeper) — single broker, fine for the lab (Ch 27).
kafka:
image: bitnami/kafka:3.7
ports: ["9092:9092"]
environment:
KAFKA_CFG_NODE_ID: "0"
KAFKA_CFG_PROCESS_ROLES: "controller,broker"
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: "0@kafka:9093"
KAFKA_CFG_LISTENERS: "PLAINTEXT://:9092,CONTROLLER://:9093"
KAFKA_CFG_ADVERTISED_LISTENERS: "PLAINTEXT://localhost:9092"
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT"
KAFKA_CFG_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
ALLOW_PLAINTEXT_LISTENER: "yes"
volumes: ["kafkadata:/bitnami/kafka"]

volumes:
pgdata:
mongodata:
redisdata:
kafkadata:

Up / down:

cd lab
docker compose up -d # start everything in the background
docker compose ps # see health
docker compose logs -f kafka # tail one service
docker compose down # stop (keeps data in volumes)
docker compose down -v # stop AND wipe data (fresh start)

Connection strings (from your host, while the lab is up):

StoreURL
PostgreSQLpostgresql://pulsely:devpassword@localhost:5432/pulsely
MongoDBmongodb://pulsely:devpassword@localhost:27017/pulsely?authSource=admin
Redisredis://localhost:6379
Kafkalocalhost:9092

The TypeScript backend toolchain​

mkdir pulsely && cd pulsely
npm init -y
npm i -D typescript tsx @types/node vitest
npm i pg ioredis mongodb kafkajs zod
npx tsc --init --rootDir src --outDir dist --module nodenext --moduleResolution nodenext --target es2022 --strict
mkdir src

package.json scripts:

{
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc",
"test": "vitest"
}
}

Verify the lab (one script that touches all four)​

src/verify-lab.ts:

import { Client as Pg } from "pg";
import Redis from "ioredis";
import { MongoClient } from "mongodb";
import { Kafka } from "kafkajs";

async function main() {
const pg = new Pg({ connectionString: "postgresql://pulsely:devpassword@localhost:5432/pulsely" });
await pg.connect();
console.log("Postgres:", (await pg.query("SELECT version()")).rows[0].version.split(" ")[1]);
await pg.end();

const redis = new Redis("redis://localhost:6379");
await redis.set("lab:ping", "ok");
console.log("Redis:", await redis.get("lab:ping"));
redis.disconnect();

const mongo = new MongoClient("mongodb://pulsely:devpassword@localhost:27017/?authSource=admin");
await mongo.connect();
console.log("Mongo:", (await mongo.db("admin").command({ buildInfo: 1 })).version);
await mongo.close();

const kafka = new Kafka({ clientId: "lab", brokers: ["localhost:9092"] });
const admin = kafka.admin();
await admin.connect();
console.log("Kafka topics:", await admin.listTopics());
await admin.disconnect();

console.log("\n✅ Lab is up — all four datastores reachable.");
}
main().catch((e) => { console.error("❌", e.message); process.exit(1); });

Run it: npx tsx src/verify-lab.ts. Four green lines means you're ready for Part IV onward.

Troubleshooting​

  • port is already allocated — something already uses 5432/27017/6379/9092. Find it (lsof -i :5432) and stop it, or remap the host side of the port in Compose (e.g. "5433:5432").
  • too many open files (you'll meet this for real in Ch 3) — raise your shell's limit with ulimit -n 4096.
  • Kafka won't connect from the host — confirm KAFKA_CFG_ADVERTISED_LISTENERS advertises localhost:9092; that's the address clients on your machine dial.
  • Apple Silicon image pulls — the images above are multi-arch; if one isn't, add platform: linux/amd64 to that service (slower, via emulation).
  • Volume permission errors — docker compose down -v and back up for a clean slate (this wipes lab data, which is fine).

← Back to Master TOC · Related: Ch 36 — Containers & the 12-Factor App