Leanpub Header

Skip to main content

Coding an Architecture Style

Remastered

Coding an Architecture Style

Most books describe architecture. This one builds it. Explore Layered, Hexagonal, Modular Monolith, and Microservices architectures through the development of a single application, implemented in Java, step by step, with all their trade-offs.

Minimum price

$15.00

$25.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
1 Previous Editionwith 230 Readers
About

About

About the Book

If you have ever had to maintain a complex "big ball of mud" enterprise application, while the business pushes for new features under an aggressive schedule, you know better than anyone how important it is to have a solid architecture. That means clearly defined rules that let us make modifications while understanding which parts of the system each change will impact.

However, it is not enough to look at beautiful architecture diagrams or to read long explanations about the benefits of microservices or modularity. Learning how to create solid structures requires solid coding practices. We have to learn which constructions our programming language offers, beyond classes and functions, to organize large applications. Only then will we be able to craft different software structures and start recognizing their benefits and drawbacks. Equally important, we have to learn how to validate the architecture rules automatically, because a diagram without enforcement eventually ends up as spaghetti code.

Throughout this book, we will iterate on a single case study, a cinema ticket system, to show how to code different architecture styles. We start with the essential concepts, such as the different views of software architecture, testing practices, and how to partition software horizontally (by technical layer) and vertically (by functionality). We also show several ways to validate boundaries, from package-private visibility to Ant, Checkstyle, ArchUnit, Maven multi-modules, and the Java Module System. Then, in each iteration, we study and implement an architecture style. We go through the layered architecture, comparing a Rich Domain Model with the classic procedural Transaction Script approach, then hexagonal (or ports and adapters), the modular monolith, and finally microservices. Before implementing microservices, we discuss the fundamental concepts behind distributed architectures, such as partial failures, the CAP theorem, two-phase commit, eventual consistency, and Sagas, together with the reasons that justify distributing a system. All of this is supported by solid architecture concepts, simple designs, and good practices, and every chapter closes with an honest discussion of the trade-offs of each approach.

We use Java 23 to implement all the styles, with Spring Boot and Hibernate, using the frameworks minimally so that the architecture does not depend on them. All the source code is available to the reader on GitHub. Although the implementation is done in Java, the same concepts can be applied in languages such as C#, Python, PHP, or Ruby.

Author

About the Author

Enrique Pablo Molinari

Enrique Molinari holds a Master in Software Engineering at Universidad Nacional de La Plata (Argentina). With 20 years of experience in the software industry he has worked in many software projects as developer, technical lead and architect. He is also professor at Universidad Nacional de Río Negro, in charge of the Object Oriented Design and Advanced Database Systems undergraduate courses.

Contents

Table of Contents

  •  
    • Preface
      • About the Author
      • What is this book about?
      • Is this book only for Java developers?
      • Assumed Knowledge
      • On Design Decisions
      • About the Code Examples
      • About this Edition
  • I Essential Concepts
    • 1 Introduction
      • What is Software Architecture?
      • Abstractions in Software Architecture
      • SEI's Architecture Structures
      • C4 Model
      • Software Architecture Styles
    • 2 Testing Practices
      • Testing and Design Styles
      • What is a "Unit" in Unit Testing?
      • Test Doubles Without Mocking Frameworks
      • Testing in Layers
      • Design for Testability
    • 3 Partitioning Software
      • Horizontal vs Vertical Partition
        • Namespaces, Packages and / or Modules
        • Logical vs Physical Separation
      • Validating Boundaries
        • Package-private
        • Ant, just use the compiler
        • Checkstyle
        • ArchUnit
        • Maven Modules
        • The Java Module System
      • Monolith vs Distributed
    • 4 Case Study: Cinema Ticket System
      • Requirements
      • API Documentation
      • On Frameworks, Libraries, and Tools Used
  • II Horizontal Partition
    • 5 Layered Architecture
      • Description
      • Rich Domain Model
        • Object-Oriented Suggestions
        • Layers Implementation
        • Testing in Layers
        • Persistence By Reachability
        • Handling Concurrency
        • Trade-Offs
      • Classic Old Procedural Layers
        • Layers Implementation
        • Repositories
        • Where to Place Exception Classes?
        • Testing
      • Trade-Offs
    • 6 Hexagonal Architecture
      • Description
      • Implementation
        • Database Transactions
      • Trade-Offs
  • III Vertical Partition
    • 7 Modular Monolith Architecture
      • Identifying Modules
      • Module Communication
        • Synchronous Method Call
        • Asynchronous Communication
      • Implementation
        • Breaking Down the Monolith
        • Analyzing Inter-Module Dependencies
        • Managing Module Communication with the Observer Design Pattern
        • The Web Module
        • Ensuring Atomic Persistence Across Modules
        • Handling Duplicated Code
        • Module Package Structure
      • Trade-Offs
    • 8 Distributed Architectures
      • Fundamental Concepts
        • Partial Failures
        • Transactions
        • The CAP Theorem
        • Two-Phase Commit
        • From Strong Consistency to Eventual Consistency
        • Ensuring Atomicity Across Heterogeneous Systems
        • Saga
      • Reasons to Distribute
      • Microservices
        • Defining the Microservices Architecture Style
        • Distributed Monolith
        • Implementation
        • Trade-Offs

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub