Skip to main content

Appendix C β€” Command & Config Cheat-Sheets

Fast, copy-paste reference for the commands you'll reach for repeatedly. Each says what it does and, where it matters, when you'd use it. Depth lives in the linked chapters.

Networking & diagnostics (Ch 5–Ch 6)​

dig api.example.com +short # resolve a name (and see the IP/CNAME chain)
dig api.example.com @1.1.1.1 # ask a specific resolver (bypass local cache)
curl -v https://api.example.com/health # see DNS→TCP→TLS→request/response, verbosely
curl -w '%{time_namelookup} %{time_connect} %{time_appconnect} %{time_total}\n' -o /dev/null -s URL # per-phase timing
openssl s_client -connect host:443 -servername host </dev/null # inspect the TLS cert chain
nc -v host 5432 # is *anything* listening on that port? (refused vs timeout)
ss -tulpn # what's listening locally (ports β†’ processes)

Reading a failed connect: connection refused = host up, nothing listening (RST). connection timed out = packet silently dropped, almost always a firewall/security group.

PostgreSQL (Ch 19)​

EXPLAIN (ANALYZE, BUFFERS) SELECT ...; -- the real plan + actual rows + page hits/reads
CREATE INDEX CONCURRENTLY idx ON t (a, b); -- build an index without locking writes
-- ESR rule: index columns in order Equality, Sort, Range.

SELECT * FROM pg_stat_activity WHERE state <> 'idle'; -- what's running now
SELECT * FROM pg_stat_user_tables ORDER BY n_dead_tup DESC; -- vacuum pressure (dead tuples)
SELECT relname, pg_size_pretty(pg_total_relation_size(oid)) FROM pg_class ORDER BY 2 DESC; -- biggest objects
psql "postgresql://pulsely:devpassword@localhost:5432/pulsely" # connect
\d+ encounters # describe a table | \di list indexes | \timing on show query time

Key knobs: shared_buffers (cache), work_mem (per-sort/hash), max_connections (and PgBouncer in front of it), autovacuum settings.

MongoDB (Ch 20)​

db.observations.find({ status: "final" }).sort({ recordedAt: -1 }).limit(20)
db.observations.createIndex({ patientId: 1, status: 1, recordedAt: -1 }) // ESR applies here too
db.observations.find({ ... }).explain("executionStats") // IXSCAN vs COLLSCAN, keys vs docs examined
db.claims.aggregate([{ $match: {...} }, { $group: {...} }]) // filter early, group late
db.collection.find({ field: { $gt: "" } }) // ⚠ classic NoSQL injection shape β€” validate inputs

Write/read concern compose: { w: "majority", j: true } for durability; readConcern: "majority" to avoid reading rolled-back data.

Redis (Ch 21)​

redis-cli # then: SET k v EX 60 | GET k | TTL k | DEL k
INCR counter # atomic increment | ZADD board 100 user (leaderboard)
INFO memory # used_memory, maxmemory, eviction stats
INFO persistence # RDB/AOF status
CONFIG GET maxmemory-policy # eviction policy (allkeys-lru, noeviction, ...)

A sliding-window rate limiter runs as one atomic Lua script (read-decide-write without a race). Distributed locks need a fencing token β€” see Redlock caveats in Ch 21.

Kafka (Ch 27)​

kafka-topics.sh --bootstrap-server localhost:9092 --create --topic activity --partitions 6
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic activity # partitions/ISR/leader
kafka-console-producer.sh --bootstrap-server localhost:9092 --topic activity
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic activity --from-beginning
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group g1 # CONSUMER LAG

Durable producer: acks=all + min.insync.replicas=2 + enable.idempotence=true. Ordering is per partition β€” choose the partition key deliberately.

Docker (Ch 36)​

docker build -t pulsely:dev . # build from the Dockerfile
docker run --rm -p 3000:3000 pulsely:dev
docker compose up -d # start the lab (Appendix A)
docker stats # live CPU/mem per container
docker exec -it <id> sh # shell into a running container
docker logs -f <id> # tail logs

Production Dockerfile rules: multi-stage (build deps stay out of the runtime image), non-root user, exec-form CMD (so SIGTERM reaches your process), copy package*.json before source (cache-friendly).

AWS CLI (Ch 37)​

aws sts get-caller-identity # who am I / which role
aws s3 cp file s3://bucket/key # object storage
aws ecs update-service --cluster c --service s --force-new-deployment
aws logs tail /ecs/pulsely --follow # CloudWatch logs
aws sqs receive-message --queue-url URL
aws secretsmanager get-secret-value --secret-id pulsely/db

Use roles + short-lived STS credentials, never static access keys in env/images/Git. Gateway VPC endpoints for S3/DynamoDB are free and keep traffic off (billed) NAT.

Node / TypeScript profiling (Ch 7–Ch 8)​

node --inspect dist/index.js # attach Chrome DevTools / VS Code debugger
node --prof dist/index.js # V8 profiler β†’ isolate-*.log β†’ node --prof-process
npx clinic flame -- node dist/index.js # flamegraph of where CPU time goes
node --max-old-space-size=512 ... # cap the V8 heap (match the container limit)
UV_THREADPOOL_SIZE=8 node ... # size libuv's pool (fs/dns/crypto)

HTTP status quick-reference (Ch 10)​

CodeMeaningUse it when
200 / 201 / 204OK / Created / No Contentsuccess; 201 with Location, 204 for deletes
400Bad Requestinput failed validation/shape
401 / 403Unauthenticated / Unauthorized"who are you?" vs "you can't do that"
404Not Foundresource missing (or hidden for authz reasons)
409Conflictduplicate/in-flight idempotent request, version clash
422Unprocessable Entitywell-formed but semantically invalid
429Too Many Requestsrate limit hit β€” include Retry-After
500 / 503Server Error / Unavailableyour bug vs "try again later" (overload, deploy)

← Back to Master TOC