Java

Chapter 150: Production-Level Java Project Structure in Java — Modules, Config, Observability, Delivery

Structure production Java services: multi-module Maven or Gradle boundaries, environment-specific config, health metrics tracing, container images, CI pipelines, and runbooks alongside code.

Author: Sushil Kumar

Java production project structureJava microservice layout MavenJava Spring Boot production configJava observability metrics tracingJava CI CD container structure

Chapter 150: Production-Level Java Project Structure in Java

Production structure is not only folders—it is how builds, config, secrets, observability, and operations line up with runtime code. Small services might stay one module; larger products split API, domain, and adapters so teams own boundaries.


1. Topic title

Production layout: code + build + deploy + observe + operate as one system


2. What it means

Repositoriessrc/main/java, src/test, Dockerfile, helm/ or k8s/, .github/workflows.

Configuration12-factor style env vars, application-prod.yaml, feature flags outside git for secrets.

Observabilitymetrics (Micrometer), traces (OpenTelemetry), structured logs (Chapter 142).


3. Why it is used

On-call engineers find runbooks and dashboards next to code reviews.

Complianceaudit trails for who shipped what artifact.


4. Mental sketch

Demo projects are backpackseverything jumbled. Production repos are tool cabinetsdrawers labeled “cutting”, “measuring”, “safety”.


5. Java code example

service/
  build.gradle.kts
  src/main/java/.../Application.java
  src/main/resources/application.yaml
  src/test/java/.../ApplicationTests.java
  Dockerfile
  README.md
  docs/runbook.md

docs/runbook.md lists “what to check when p99 spikes”living document.


6. Explanation of code

Single Application.java entry per deployable artifactmultiple main classes confuse packaging.


7. Common mistakes

Prod secrets in gitrotate and use secret manager.

Skipping README run instructionsfirst day pain tax.


8. Best practices

Versioned API changelog + semantic versioning for libraries.

SBOM and dependency scanning in CIsupply chain hygiene.


9. Small practice task

Add /actuator/health readiness check that includes database pingwire Kubernetes readinessProbe path.


Beginner tip

If docker build works but Kubernetes crashes, check JAVA_TOOL_OPTIONS, memory limits, and file system read-only rootsruntime differs from laptop.