↓Skip to main content
  1. Posts/
  2. The Code Citadel - Introduction/

The Code Citadel - The Fall of the Keep

·18 mins·
Motte and Bailey

For centuries, the Castle was the pinnacle of architectural achievement. It stood as a singular, self-contained universe where every vital function - from defense and housing to governance and storage - was tightly integrated behind massive, impenetrable walls.

Once the foundation was laid and the stone set, the structure defined the landscape, creating a powerful fortress. These imposing structures were built to be immovable and permanent, prioritizing absolute stability. It was an engineering marvel designed to rely on nothing but itself, creating a fortified ecosystem.

It was the ultimate expression of centralized control, a massive, unified entity that dominated its environment. Inside, life was strictly ordered and interconnected; a change in the royal court rippled instantly through the barracks and the kitchens, just as every stone relied on the one beneath it.

In the digital realm, we call it the Monolith. Like the great Norman Castles or Keeps of the 12th-16th century, the Monolith is a structure of singular purpose and unified strength. It is the “Majestic Monolith,” a fortress where every component - from the scullery of the data access layer to the high towers of the user interface - resides within a single, impregnable perimeter.

The advantages of the Castle are undeniable. Governance is absolute; the Castellan (the compiler) knows the location of every servant and every soldier. Resources are shared; the Great Hall serves as a central hub where data is exchanged instantly, with the “latency” of a whisper across a table. The Treasury (the Database) is a single, locked vault. When gold is moved, it is moved atomically. There is no doubt, no ambiguity, no “eventual consistency.” The Castle is safe.

Prologue: The Wisdom of the Motte #

Every story of any company, any service, or any system begins with an idea, which can be compared to finding the perfect location to build a future fortress.

Motte and Bailey

While, it’s an interesting story on how it was built, at the beginning of our story, there was only the Motte and Bailey (at least, many of you joined companies where it was already).

Motte and Bailey

In the landscape of medieval architecture, this was the MVP (Minimum Viable Product). It was a simple earthen mound (the Motte) topped with a wooden tower, surrounded by a defensive palisade (the Bailey). The construction was simple and functional, the only thing needed to perform the main function. In the Motte was the Counting House, with a single, sturdy room. Inside this room sat your entire architecture: a single Master Clerk named Edmund (The Monolith) and his Great Ledger (The Database). It did work. It worked perfectly and efficiently.

Take a look at one of example:

A client - a wool merchant - enters and asks: “What is the rate to ship ten bales of wool from London to Pisa, including tolls and the exchange rate of the Florin?”

Master Clerk Edmund does not need to send a letter to a foreign office. He does not need to wait for a reply. He simply reaches across his desk, opens the Pratica della mercatura (the book of trade rates), looks up the London toll, flips the page to the Pisa exchange rate, and calculates the sum.

  • Zero Latency - the data is within arm’s reach (In-Memory/Local Disk). The communication between “Pricing” and “Inventory” happens inside the Clerk’s head.
  • Transactional Integrity - he writes the deal in the Ledger. If his quill breaks halfway through, he stops. The transaction is either recorded or it isn’t. There is no risk that the London office thinks the deal is done while the Pisa office thinks it failed.
  • Simple Deployment - if you need to update the rates, you don’t need to coordinate twenty different scribes in twenty different cities. You just hand the Clerk a new book. One Book to One Clerk.

For a time, the Counting House is not just sufficient; it is magnificent. It is fast, consistent, and cheap.

It was crude, cheap to construct, and undeniably effective.

In software engineering, this is the early-stage startup. The architecture is a single codebase - a “Monolith.” Like the Motte, it is designed for survival and speed. We often look back at these early structures with disdain, viewing them as primitive. But we must acknowledge their initial genius. The Motte provided unified governance and absolute clarity of purpose. For a time, it was not just sufficient; it was perfect.


The Age of Stone: The Majestic Monolith #

The Age of Stone: The Majestic Monolith

As the Kingdom and your Company prosper, the Counting House expands. You replace the wood with stone. You build The Keep.

The era of Keeps and Castles, known to historians as the High Middle Ages, corresponds most accurately to the era of the Majestic Monolith. 

It is easy, in the midst of our modern struggles with distributed complexity, to forget the sheer elegance of the Great Keep. It was a masterpiece of vertical integration, a structure where every component - from the scullery (the data access and processing layer) to the high towers of the user interface - resided within a single, impregnable perimeter… It is a single executable, a unified deployment unit where the Interface, the Search Logic, the Pricing Engine, and the Booking System all reside within the same defensive walls.

The Great Hall: The Luxury of Local Calls #

The Great Hall: The Luxury of Local Calls

The heart of the Keep is the Great Hall. In the Royal Travel Service, this is the application runtime.

Imagine the King (The User) demands a complex itinerary: “Find me a route from York to Rome, avoiding the French war zones, with stops at decent inns.”

At the current scale, adding the new capabilities wasn’t so difficult, so you’ve easily hired the required specialists (added new functionality).

In a distributed system (Microservices), this request would be a nightmare. The “Route Service” would have to message the “War Zone Service,” which would message the “Inn Service,” all over a treacherous network. But in the Majestic Monolith, the Chamberlain (The Code) does not need to travel to a different village; he does not need to negotiate a trade treaty; he does not need to worry if the road is washed out. He pours the wine and simply walks across the Great Hall.

  • He asks the Map Master (Route Module) for the path from York to Rome.
  • He asks the War Scout (Risk Module) for safety data.
  • He asks the Innkeeper (Hotel Module) for availability at The Golden Lion in Florence and The Silver Stag in Lyon.

They are all standing in the same room. They share the same memory. Master Clerk Edmund can assemble the complete itinerary in milliseconds end to end.

This is the beauty of Inter-Process Communication (IPC). In the Monolith, different modules live in the same memory space. Calling a function is as fast as a whisper across the table. There is no network overhead, no serialization of JSON, no handshake. The “Fallacies of Distributed Computing” - that the network is reliable, or that latency is zero, and etc. - do not apply here, because there is no network. 

The system is lightning fast because the distance between intention and execution is microscopic.

The Royal Treasury: The Absolutism of ACID #

The Royal Treasury: The Absolutism of ACID

Deep within the donjon (a massive inner tower in a medieval castle) lies the Royal Treasury. This is your monolithic Database. The Monolith enjoys a privilege that modern distributed systems struggle to replicate: ACID Transactions (Atomicity, Consistency, Isolation, Durability).

Let us say a client books a journey. You must:

  1. Deduct gold from the Client’s account.
  2. Reserve a seat on the ship.
  3. Pay the toll collector.

In the Keep, the Royal Treasurer opens the single Great Ledger. He dips his quill. He performs all three steps in one continuous motion. Crucially, if the castle catches fire (System Crash) after step 2, the Treasurer simply burns the page. The transaction never happened. The gold is not lost; the seat is not double-booked.

Or… Consider the collection of taxes. The Sheriff brings 50 gold coins from the village.

The Royal Treasurer opens the Great Ledger.

  1. He dips his quill.
  2. He subtracts 50 coins from the Village debt.
  3. He adds 50 coins to the King’s Vault.

The Royal Treasurer closes the Great Ledger.

The state of the world is consistent. There is only one Ledger. There are no arguments about who owns what, because there is only one room where ownership is recorded. The residents of the Keep sleep soundly, knowing that the state of the world is consistent. There is no “Two Generals Problem” here, because there is only one General and one Ledger.

The Walls: The Simplicity of Defense #

Defending the Keep is straightforward.

The Walls: The Simplicity of Defense

First of all, let’s see what you have and what you have to worry about:

  • You had one perimeter: the Curtain Wall.
  • You have entry point: the Drawbridge (The Public API / Load Balancer).

The curtain walls are so high and strong that nobody can climb so high and so thick that nobody can make a hole. Around the keep, you have a deep and wide moat with water (hopefully only water), and there is no way to cross without being detected. You inspected the whole keep, and you know for sure that there are no hidden holes, and you need to secure the only main entrance.

To secure the Monolith, you posted your guards (Firewalls/Authentication) at the Drawbridge. Once a visitor passes the guards - they are authenticated - you trust them. They could walk from the stables to the kitchen without being stopped again. The Cook can talk to the Treasurer without showing a badge every time. You do not need to secure traffic inside the castle.

This “Hard Shell, Soft Center” security model is incredibly efficient to manage. You focus all your guards on the front gate. The Castellan (The Ops Team) doesn’t need to coordinate security policies across fifty different guard towers in fifty different towns. They don’t need “Zero Trust” architecture between your Booking Class and your Pricing Class. There is only one set of keys. If the drawbridge is up, the system is safe.

The Joy of the Castellan: Operational Simplicity #

For the Castellan (The DevOps/Ops Team), the Keep is a joy to manage.

The Walls: The Simplicity of Defense

For example:

  • Deployment: Everything inside, within the Curtain Wall, and when you add a new feature - say, “Search by Carriage Type” - you compile the code into one artifact (a single binary). You lower the banner, raise the new one, and you are done. You do not need to orchestrate the upgrade of fifty different services in a specific order. You don’t need Kubernetes.
  • Resources Management: You stay in the single perimeter, and you see where you have to add/remove resources. You can observe everything from the single tower.
  • Debugging: If the booking fails, the Castellan walks into the cellar (The Log Files). He reads one scroll. The error trace is a single, unbroken line from the user’s click down to the database query. He does not need to chase ghosts across a distributed network.

The Majestic Monolith is strong. It is fast. It is unified. It is the pinnacle of the Age of Stone.


The Sprawl: The Crisis of the Bailey #

But stone walls, unlike software requirements, cannot expand indefinitely.

Success became the Keep’s undoing.
The Walls: The Simplicity of Defense

The Kingdom grew.

The King wanted new features: a jousting tournament, a falconry, a larger kitchen, and a new wing for the foreign ambassadors.

The ambition of a travel startup grew as well. Well, fairly to mention that the King enjoys traveling and forced those ambitions grow. Your “Travel Search Engine” becomes a victim of its own success. The King demands more. He wants to travel to a new destination. He also wants to book not just carriages, but ships, horses, and mercenaries. He wants to have more taxes paid, so dynamic pricing based on the weather seems a great problem resolution. And… the King just recently ordered an iPhone app for his knights.

However, the King and his requirements were not the only ones, and the company was searching for solutions to problems raised by many users. During the kingdom’s rise, you expanded the range of services for many of the King’s subjects and their expectations grew as well.

The Keep began to fill up. More carriages and horses were needed. Inns quickly overflowed. Guests had varied preferences, and the kitchens were under increasing pressure. You needed more supplies, more storage capacity to meet the needs of both the fortress and the guests, and to stock the wagons with food. You were constantly forced to expand… Master Clerk Edmund can no longer work alone; he has hired 300 assistants. They are all elbowing each other in the Great Hall. And thus began the era of The Sprawl.

The Shantytown of Dependencies #

The Walls: The Simplicity of Defense

When the Keep could hold no more, you started building in the Bailey. To accommodate the new features, you build lean-tos in the courtyard between the Keep and the outer wall. You build a “Mercenary Booking Shack” on top of the “Horse Stable.” To save stone (code reuse), the new “Dovecote” was built using the back wall of the blacksmith’s forge and extended onto the forge’s roof. This represents Tight Coupling and Spaghetti Code. When you saw impossible or not rational to add a new building (Module), then you made some shortpaths in the present ones. The small if wasn’t seems harmful behind a Great Pressure of the Keep’s Bailey’s size limits.

Sometimes, you decided to adjust the usage of the presents buildings. When the King lost his interest to the falconry, you decided to re-use the building for the “Mercenary Booking Shack”. The Walls and Keep was under the pressure of constant and never stoping renovations and reconstruction (Refactoring), which was way more difficult to justify, because a damage was more and more visible and it was more difficult to make a change.

In the overcrowded Monolith, modules are no longer neat, separate rooms. They are shanties leaning on one another… Because everyone lives in the same Keep, they start borrowing each other’s tools without asking. The “Carriage Module” starts reading directly from the “Hotel Module’s” private notebook. The “User Profile” module borrows a column from the “Billing” table. The “Reporting” module reaches directly into the private memory of the “Inventory” module.

One day, a junior smith changes the shape of a horseshoe (a small code change in a utility library). Suddenly, the carriages stop working. The horses go lame. The entire travel network collapses. The dependencies are invisible and deadly.

The result is fragility. If the Blacksmith lights a hot fire to forge a sword, the heat penetrates the wall and the roof, and kills the pigeons on the other side. A developer changes a line of code in the “Invoice Printing” class, and inexplicably, the “User Login” fails. The dependencies are invisible, organic, and terrifying.

The Stench of the Garderobe (Technical Debt) #

Let us speak of sanitation.

The Walls: The Simplicity of Defense

In the early Keep, waste was managed easily by shafts called garderobes.

But as the population within the walls exploded, the shafts clogged. With 300 clerks, the Garderobes (toilets) clogged faster than the new cleanup was refined and planned, and every time this operation was performed, there was not enough time to clean up everything completely. So, the waste (technical debt) started accumulating and the cost of having it (the smell) and budgets for re-construction (redesign) explodes quickly.

Code written five years ago - the “Foundation” - sits at the bottom of the tower. Due to an essential effort for operational work with the Garderobes, nobody saw it possible to perform a regular inspection of the Foundation, and soon it became even more difficult to do because the stagnant foul smell. The old wood Foundation is rotten, but it supports the weight of the Great Hall. Code that was written ten years ago - the “Legacy Foundation” - sat at the bottom of the structure, untouchable and misunderstood. To fix a bug in the foundation was to risk bringing down the entire tower. No one dares to touch it. So, the inhabitants learned to live with the stench.

They built layers of abstraction (perfume) over the rot.

New developers (squires) joined the castle and spent months just learning how to navigate the maze of hallways without stepping in filth.

Velocity slowed to a crawl.

The Siege of Traffic: Vertical Scaling Limits #

The Walls: The Simplicity of Defense

But then came gunpowder and the enemy army came: The Traffic Spike.

The Castle has only one Well (The Database). During the siege (the Spring Festival), every resident - from the soldier to the cook - needs water simultaneously. The Royal Travel Service, once handling 500 bookings per day comfortably, now faces 5,000 bookings per day. Master Clerk Edmund and his 300 assistants crowd around the single shaft. Everybody lowers their bucket into the same shaft. The ropes get tangled. Arguments break out.

The Castellan (The DevOps/Ops Team) tries to solve this. He digs the well deeper (Faster CPU). He is making the bucket bigger and bigger (vertical scaling / more RAM). But there is a physical limit to how big a bucket you can hoist.

Eventually, the Monolith simply cannot serve enough water. Edmund and his 300 assistants are overwhelmed.

Suddenly, the very distinctives that made the Castle legendary - its towering height and rigid, stone permanence - became its undoing. Against the explosive, rapid-fire traffic spikes, the castle was no longer a fortress; it was merely a large, static target.

The Castle cannot scale… The knights riot.

In our digital landscape, this ‘gunpowder’ arrived in the form of Cloud Computing and Agile methodologies. Just as cannons forced architects to stop building up (vertical scaling) and start building out (horizontal scaling), the demands of the modern web exposed the monolith’s fatal flaw: it was too heavy to move and too brittle to withstand the shock of constant change.

The Fear #

Finally, the most paralyzing symptom of the Sprawl: The Fear.

The Walls: The Simplicity of Defense

Because the Castle is one solid block of stone, with many dependencies and risk of wall (or tower) collapse, you cannot renovate the kitchen without closing the entire castle.

To deploy a small fix for the “Carriage Search,” you must redeploy the entire application.

To deploy a new version of the Monolith, you must raise the drawbridge, kick everyone out (Downtime), and hope the new structure holds.

Because the system is so complex, no single person understands it all. Deployments become “Big Bang” events, planned months in advance, performed at midnight on weekends.

The residents are angry. The knights are still rioting. They require explanation from the Castellan (The DevOps/Ops Team) and the Architect.

The Castellan’s (The DevOps/Ops Team) anxiety poisoned even the language of the court. In the Golden Age, the architects circulated RFCs - noble Requests For Counsel - seeking wisdom from every mason and smith. But as the fear of failure grew, these scrolls were twisted. They first hardened into Requests For Commitment, demanding blood oaths of certainty in an uncertain world. Finally, in the darkest days of the siege, they became Receipts For Culpability: paper trails forged solely to identify which sorcerer to burn when the magic inevitably failed.

The Castle, once a symbol of strength, has become a prison.

The Architects are terrified.


The Decision: To Build the Bastide #

The Walls: The Simplicity of Defense

The Chief Architect stands on the battlements, looking down at the chaotic, overcrowded, smelly Bailey. He sees the servants tripping over each other. He sees the cracks in the foundation. He realizes that Vertical Scaling - building the tower higher - is no longer physics-compliant.

He looks out to the horizon, to the green fields beyond the moat. He makes a radical decision. “We cannot save the Castle,” he declares. “We must build a City.”

This is the transition to Microservices. Historically, this mirrors the founding of the Bastides in 13th and 14th-century France. Unlike the organic, huddled growth of the old bourgs, Bastides were planned new towns. They were instruments of economic expansion, built on a grid.

The Charter of the New City #

The Walls: The Simplicity of Defense

The Architect draws a new map. It is not a single building, but a federation of specialized structures.

  1. Decomposition: We will move the Blacksmiths to their own district (The Inventory Service). We will move the Bakers to theirs (The Order Service). We will move the Carriage Masters to their own district (The Transport Service). We will move the Innkeepers to theirs (The Hotel Service).
  2. Autonomy: If the Blacksmiths need to expand, they can build a new forge without asking the Bakers for permission. If the Bakers burn down their ovens, the Blacksmiths can keep working. This is Fault Isolation.
  3. The Grid (API Contracts): The districts will not be connected by secret hallways. They will be connected by public roads (The Network). Interactions will be governed by a Charter (The API Definition), ensuring that the Blacksmith knows exactly what the Baker needs.

The Trade-Off #

The Walls: The Simplicity of Defense

The Architect knows this decision is dangerous and comes with a heavy price. In the Castle, he was safe behind thick walls. He had one well, one ledger, and zero latency. In the City, he is exposed. He has traded the Complexity of Code for the Complexity of Logistics.

  • He will have to build roads (Network Infrastructure).
  • He will have to worry about bandits (Security).
  • He will have to hire runners to carry messages between the districts (Latency).
  • He will lose the Royal Truth of the single Ledger (Eventual Consistency).

“The Castle was safe,” the Architect writes in his chronicle. “But the Castle was a tomb. We choose the danger of the City for the promise of growth.”

In the next chronicle, Roads of Mud and Stone, we will explore the terrifying logistics of the medieval road network, and why the King can no longer simply whisper for his wine.