Explore
Module 1 · Part 1 of 12 · Free preview

Part 1

Chapter 1: The Immutable Awakening...--–- On my third day as a junior backend developer, I deleted the production user table. Not through malice, not through a sophisticated SQL injection attack, but through the humble, predictable failure of assuming that data I passed around couldn't be changed by someone else's code. A method deep in the call stack had received my User object, decided to set its email to null as part of some internal logic, and returned the same object instead of a copy. Twenty thousand users woke up to password reset emails they didn't request. The CTO asked me one question: "What did you assume that you shouldn't have?"That question became the thesis of this entire book.

Backend engineering is not about knowing the most frameworks or writing the cleverest one-liners. It is about understanding where your assumptions live, documenting them explicitly, and building systems that fail in ways you can predict and recover from. Most junior developers know the syntax of Java—loops, classes, if statements, maybe a stream or two. But they struggle to write code that survives the chaos of production: concurrent requests, partial failures, network partitions, and the inevitable moment when another developer (or their future self) modifies a method they thought was safe.This chapter reorients you from "writing Java that compiles" to "writing Java that survives."

We will tear down the illusion that object-oriented programming is about modeling real-world things and rebuild it as a discipline of boundaries and contracts. We will modernize your Java instincts from the Java 8 era to Java 17+ with features that eliminate entire categories of bugs: Records for immutable data carriers, Sealed Classes for controlled hierarchies, and Optional for banishing null pointer exceptions from your API boundaries. And we will establish a critical distinction that will save you from my production disaster: the separation between domain models for business logic (which may need mutability for JPA) and contract models for APIs and events (which should be immutable Records).By the end of this chapter, you will have defined the immutable core of our e-commerce backend—Product, User, Order, and OrderStatus—using modern Java patterns that communicate intent, enforce invariants, and make the "what did you assume?" question answerable.

Keep reading — free

Sign in with your SamEnrico account to read the whole of lesson 1.

Sign in