Skip to main content

Beyond the Tools: Building Infrastructure vs. Using It

Updated 4 min readMarkdown

There's a difference between using infrastructure tools and building something that behaves like infrastructure. This project taught me that difference the hard way.

The plan was to build a self service sandbox platform. Users spin up isolated temporary environments, apps get deployed into them, a chaos engineering toggle lets you simulate outages, a health monitor watches everything, and when the TTL expires the platform cleans itself up automatically. Single Linux VM. One command to start.

Here's what I actually learned.

Nginx is more powerful than I gave it credit for

I've always used Nginx as a static config thing, write the config, restart, done. But this project forced me to treat it as a dynamic component. Every time an environment gets created, a script writes a new location block to nginx/conf.d/$ENV_ID.conf and runs nginx -s reload On destroy, the file gets deleted and Nginx reloads again.

No downtime. No manual intervention. The whole routing table rebuilds itself on every create and destroy.

That shift from Nginx as config to Nginx as a programmable router, changed how I think about it entirely.

Atomicity matters more than you think

Early on I was writing state files directly. Worked fine until I had a cleanup daemon reading those same files at the same time a create was writing them. Partial reads, corrupt JSON, daemon trying to destroy an env that was still being built.

The fix was simple write to a .tmp file first then mv it into place. mv on Linux is atomic at the filesystem level. One line change, problem gone. But it taught me something, in distributed-ish systems (even ones running on a single VM), the order and atomicity of writes matters from day one, not as an afterthought.

Process ownership is a real thing

Approach A for log shipping is simple, run docker logs -f $CONTAINER >> app.log & and store the PID. Kill it on destroy. What I didn't think about initially: docker logs runs as root, so it writes the log file as root. When the cleanup daemon (running as my user) tries to rm -rf the log directory, it gets permission denied.

The environment never actually gets destroyed, the daemon just keeps retrying it forever. The fix was one line chmod -R 777 before the delete. But the lesson is that you have to think about who owns what in a system with multiple processes touching the same files.

Chaos engineering is just controlled observation

I thought the chaos engineering part would be the flashy fun bit. And it is. But building it made me realize what it's actually for, it's not about breaking things. It's about verifying that your observability works.

The crash mode kills the container. The health monitor should catch it within 90 seconds. The state file should update to degraded, The logs should show the failure timestamps. If any of those don't happen, your monitoring is broken and you'd rather find that out during a controlled test than during an actual incident.

Building the chaos tooling made me take the health monitor way more seriously than I would have otherwise.

The safety guard is not optional

There's a check at the top of simulate_outage.sh that hard-exits if you try to run chaos against an infrastructure container, Nginx, the API, the daemon itself. I almost didn't build it because "I'll just be careful."

Then during testing I nearly ran make simulate MODE=crash against the wrong container name. Added the guard immediately.

The lesson, In any system with destructive operations, the safeguards aren't for when you're being careful. They're for when you're not.

What I'd Build Differently

The log shipping approach works but it's fragile, if the VM reboots, the log shipper process doesn't come back. I'd switch to Loki + Promtail in a proper setup. I'd also add authentication on the API (right now it's open to anyone on the network) and Prometheus metrics on the health poller so you can actually graph degradation over time.

But the core architecture, dynamic Nginx, isolated Docker networks per env, TTL-based cleanup, atomic state files, I'd keep all of that.

Repo is on GitHub at https://github.com/ahlbertng/devops-sandbox if you want to dig into it. The README has a full walkthrough from zero to first running environment.

10 views

No comments yet. Be the first to comment.