Video in progress

The server's disk filled up on prod. How should the service behave, and how do you design for it in advance?

A full disk is not one service's bug but the whole host's: logs, temp files and the DB WAL fail at the same time. You think about it ahead of time: a limit on everything that writes to disk, monitoring, and a clear behavior when the disk is full (reject writes, turn off readiness).

📖 Answer

IOException: No space left on device often shows up in the most unexpected place: the logger can't write, Tomcat can't create a multipart temp file, PostgreSQL can't write the WAL and stops. On top of that, since nothing gets logged, you can't even see what is going on.

Common causes in practice:

  • no log rotation, or rotation only by size with an unbounded total (totalSizeCap not set);
  • a deleted but still open file: df shows full while du says otherwise; lsof +L1 finds it, and the space is freed only when the process closes it;
  • temp copies of uploaded files not cleaned up;
  • a heap dump (-XX:+HeapDumpOnOutOfMemoryError) dropped 8 GB onto the root disk.

Design rules:

  1. Separation. Keep data, logs and temp on different disks or volumes. If the logs fill up, the database should not stop.
  2. A limit on every consumer. SizeAndTimeBasedRollingPolicy + totalSizeCap in Logback, a cleanup job for temp directories, an ephemeral-storage limit in Kubernetes.
  3. Monitoring. Alert not on the percentage of free space but on the fill rate: "at this pace it fills up in 6 hours". A rule based on predict_linear over node exporter metrics fits this.
  4. Graceful degradation. Before writing, the service checks Files.getFileStore(dir).getUsableSpace(), and below the threshold it rejects new uploads with 507/503 and turns off the readiness probe, so the load balancer routes traffic to another instance. This is better than half-written files and a corrupted state.
  5. A reserve. Some teams keep a "ballast" file of a few GB on disk, to delete it in an emergency and free space immediately.

After the incident the question should not be "which file do we delete" but "why was there no limit"; otherwise it all happens again in a month.