How One Deployable Application Can Keep Business Modules Separate
At a small workshop, two people ask to borrow the same cordless drill. Both saw “Available” on the website. Only one can leave with it. The application needs to decide who gets the drill and record the loan. If saving the loan fails, the drill needs to stay available.
We’ll give Equipment Catalog and Lending clear responsibilities inside one Java web application. Then we’ll see what changes if those modules run as separate services. You’ll follow an HTML form all the way to the database and test what happens when the application fails halfway through.
If you’ve written Java classes and interfaces and want a refresher on packages and visibility, start here. Java for Beginners
1. What runs where?
Java SE is the standard Java platform. The Java Development Kit (JDK) gives you a compiler and the Java Virtual Machine (JVM) that runs the compiled code. Java SE gives the workshop app language features and libraries such as strings and lists.
Jakarta EE defines contracts for server applications. A contract defines what an API exposes and what behavior an implementation must provide. In this app, Jakarta Faces turns templates into HTML, Jakarta Contexts and Dependency Injection (CDI) supplies objects such as the catalog service, Jakarta Validation checks form inputs, and Jakarta Persistence maps Java objects to rows in a database. Jakarta Transactions, commonly called JTA, coordinates work that commits or rolls back as a unit. Jakarta EE continues Java EE at the Eclipse Foundation. Jakarta EE 8 retained the old Enterprise Edition packages, and Jakarta EE 9 moved those APIs from javax.* to jakarta.*. Java SE packages such as javax.sql retain their names. Jakarta EE 11 Platform specification · Jakarta EE 9 release
WildFly is an application server. It runs on the JDK, receives requests and provides implementations of the Jakarta APIs. Maven compiles and packages our code as a web application archive, or WAR. This ZIP-format file contains compiled application classes, settings and web templates. WildFly deploys it by registering and starting the application. The WAR is named workshop.war, so the default address starts with /workshop/. WildFly Getting Started Guide
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>11.0.0</version>
<scope>provided</scope>
</dependency>
Maven uses this dependency to compile code such as import jakarta.inject.Inject;. The provided scope leaves the API dependency out of the WAR. WildFly supplies the APIs and implementations at runtime. The API dependency alone cannot start a server. Maven dependency scopes
A profile describes APIs. A configuration chooses what runs.
The Jakarta EE 11 Web Profile specifies the APIs needed for web applications like ours. The Jakarta EE 11 Platform covers a broader set, including Jakarta Messaging and the full Enterprise Beans specification. The smaller Core Profile targets fewer APIs and does not cover this lab. WildFly’s standalone.xml and standalone-full.xml are concrete server configurations with different enabled subsystems. For example, the regular distribution’s standalone.xml includes the Enterprise Beans timer service and omits the messaging subsystem. standalone-full.xml includes ActiveMQ Artemis messaging. An Enterprise Beans Lite application cannot assume Timer Service portability from the Web Profile alone. Web Profile 11 specification · Platform 11 specification · WildFly 42 Admin Guide
| Task | Jakarta EE API or WildFly function | What the application still owns |
|---|---|---|
| HTTP and rendering | WildFly’s Undertow HTTP server, Servlet and Jakarta Faces. Facelets are templates for server-rendered views. | Pages, labels, actions and error messages. |
| Dependency injection | CDI manages objects and supplies collaborators at declared injection points. | Interfaces and which responsibilities may call one another. |
| Input validation | Jakarta Validation, often called Bean Validation, integrates with Faces. | Field constraints and separate rules about equipment and loans. |
| Persistence | Jakarta Persistence and an injected EntityManager load and store mapped objects. |
Data model, ownership, queries and concurrent update rules. |
| Transactions | JTA and @Transactional give managed method calls transaction boundaries. |
Which changes must succeed together and how failures are handled. |
| Database access and pooling | A WildFly-managed JDBC DataSource supplies connections using a configured driver, URL and pool of reusable connections. |
Database, credentials, compatible schema, migration strategy and pool sizing. |
| Security | Jakarta Security is in the Web Profile. WildFly can use Elytron and configured identity stores. | Authentication setup, authorization rules and who may borrow or return items. The lab uses fictional names and has no login. |
| Messaging | Jakarta Messaging belongs to the Platform. WildFly’s full standalone configuration enables the messaging subsystem. | Broker and destinations, message contracts, retry behavior and duplicate handling. |
| Timers | Full Enterprise Beans defines timer services. WildFly includes a timer service in the lab’s server configuration. | Schedules, restart semantics and making repeated jobs safe. |
Run the lab on regular WildFly 42.0.0.Final, using standalone.xml. The release announcement lists EE 11 Platform, Web and Core Profile compatibility on Java SE 17 and 21. It recommends Java 25 for general use and gives the compatibility evidence for 17 and 21. The regular 42 release uses EE 11. The release announcement and variant guide confirm that the temporary WildFly EE 10 distribution ended with 41, despite stale variant wording in the Getting Started Guide. As of 23 November 2026, the official downloads listed 42.0.0.Final, and Adoptium listed Temurin 21.0.13.1+2 as its latest JDK 21 patch. The lab pins Jakarta EE Web API 11.0.0, targets Java 21 and uses H2 2.4.240 from the WildFly distribution. WildFly downloads · Release and compatibility evidence · WildFly variants · Temurin release
WildFly’s official kitchensink quickstart shows how Faces, CDI, persistence and validation fit in a web application. Here we use the same server-side building blocks for a workshop and define explicit boundaries between its two business modules. WildFly 42 kitchensink source
2. Give each module a job
A modular monolith, sometimes called a modulith, is one deployable application made up of business modules with controlled dependencies. Equipment Catalog owns each item’s ID, name and availability. Lending owns who borrowed the item and whether the loan is active or returned. A loan stores the equipment ID as a value. It does not use a Java reference to another module’s persistence object. Both modules use the same database in this lab and write only their own tables.
lab/
├─ pom.xml one build, one WAR
├─ src/main/java/com/homannsoftware/workshop/
│ ├─ catalog/
│ │ ├─ api/EquipmentCatalog.java item view, checkOut, checkIn
│ │ └─ internal/ Equipment, JpaEquipmentCatalog
│ ├─ lending/
│ │ ├─ api/Lending.java borrow, returnItem, loan history
│ │ └─ internal/ Loan, JpaLending
│ └─ web/WorkshopPage.java uses both public APIs
├─ src/main/resources/META-INF/ database mapping and seed SQL
├─ src/main/webapp/index.xhtml Facelets page with both forms
└─ src/test/java/…/ModuleBoundariesTest.java
A module’s API is the set of types and operations its callers may use. These are Java interfaces and small read-only records. The web layer asks the catalog for a display list and calls Lending to borrow or return. Lending may call the catalog API. The catalog has no dependency on Lending or the web layer.
The persistence entities, which are Java classes mapped to database tables, have package visibility. Java prevents other packages from naming them. The CDI implementation classes are public for use by the runtime, so Java visibility alone leaves an opening for accidental coupling. The Maven build runs an ArchUnit test over compiled classes. It rejects dependencies on internal classes from other packages, including a field of type JpaEquipmentCatalog inside JpaLending. It also rejects a catalog dependency on Lending or web code and a Lending dependency on the web layer. The test checks Java dependencies. Module ownership still has to guide SQL, schema design and code review. ArchUnit user guide · Learning Hub guide to business boundaries and Spring Modulith
3. Follow one form submission
- Open the page. The browser sends an HTTP GET. WildFly hands it to Faces. Faces reads
index.xhtml, a Facelets template. Expressions such as#{workshopPage.items}ask a Java object for data. Faces sends the browser the finished HTML with the catalog and forms. - Submit the form. Pick “Cordless drill”, enter “Alex” and press “Borrow item”. The browser sends an HTTP POST. Faces reads the submitted values, converts the equipment ID to a number and validates the inputs. A blank name can fail Faces’ required check or the
@NotBlankconstraint. A name of 61 characters fails@Size(max = 60). Faces displays the field error and skips the borrow action. Jakarta Faces request lifecycle · Jakarta Validation 3.1 - Call the business operation. On valid input, Faces sets the values on
WorkshopPageand invokesborrow(). CDI creates a request-scoped instance, which lives for that HTTP request, and injects an implementation of theLendinginterface. The page passes the ID and borrower name through that interface. - Make both changes. The transaction interceptor starts a JTA transaction for the managed Lending call when none already exists. Lending calls
catalog.checkOut(equipmentId). The catalog requires the existing transaction and takes a database write lock on the equipment row before checking availability. This makes competing requests wait their turn for the same item. The catalog marks it unavailable and Lending creates a loan. Both use the same JTA persistence unit and managed DataSource against one database. Jakarta Transactions 2.0 · Jakarta Persistence 3.2 - Render the result. The successful call commits before the page action returns a redirect. The browser follows it with a fresh GET. Faces rereads the catalog and loan history, then renders “Loan recorded”, “On loan” and an active loan. The redirect lets someone refresh the result page without submitting the form again. Returning an item makes the catalog available and closes the active loan in another transaction.
If Pat submits a valid form for the same drill, the request can pass field validation and still fail. Whether the drill is available depends on the stored state when the catalog acquires the lock. Lending reports “This item is already on loan” and Faces renders that business error on the same page. The select menu keeps equipment visible in either state so you can reproduce the rule. A page loaded before someone else borrowed the drill would present the same real-world problem.
See what rollback does
Here is the write portion of the Lending method. The full implementation also checks the borrower name for callers outside Faces and translates catalog rejections into Lending errors.
import jakarta.transaction.Transactional;
@Transactional
public void borrow(long equipmentId, String borrower, boolean simulateFailure) {
// Input checks and catalog error translation omitted in this excerpt.
catalog.checkOut(equipmentId);
entityManager.persist(new Loan(equipmentId, borrower.strip()));
if (simulateFailure) {
entityManager.flush();
throw new LabRollback();
}
}
The catalog method uses @Transactional(Transactional.TxType.MANDATORY), which requires the calling transaction. The lab fault is an unchecked exception. It crosses the transactional method’s boundary before the web layer catches it, so the transaction interceptor rolls back the writes. flush() sends pending SQL to the database during the transaction. Commit is the step that makes the changes durable in a durable database. In the learning configuration, the data lives in memory. Sharing a WAR alone would not make these writes atomic. The managed call, shared transaction and database are what give the operation its all-or-nothing behavior. Jakarta Transactions Transactional contract · Learning Hub guide to transactions and rollback
Borrow the multimeter as “Rollback test” with Simulate a transaction failure checked. After the error, open the page again in a fresh request. The multimeter should still show “Available” and the loan history should have no row for “Rollback test”. These values come from fresh database queries through both module APIs. Submit the same loan with the box unchecked and it should succeed.
4. One deployment can run on several machines
In the lab, both modules share one WildFly runtime and release as one WAR. The runtime is the server process with its managed services. The release unit is the artifact that moves through testing and deployment. An instance is a running copy. You can run the same WAR on several instances across machines. Each instance gets its own server process. Production replicas need a shared persistent database in this design and a deliberate way to handle browser sessions and Faces view state, such as session affinity or configured session replication with tested failover. Replicas using their own in-memory H2 databases would disagree about who has the drill. WildFly High Availability Guide
One WAR means one application build artifact. A call from Lending to Catalog stays within the same process. There are fewer independent releases to coordinate, and local data consistency is easier to enforce. The trade-off is a shared release cadence, shared CPU, memory, threads and database connections, and a larger common failure area. For example, a catalog page that saturates the pool could slow returns. An outage in the shared database could stop both modules regardless of how many server instances are running.
5. What changes with two deployments?
| Decision | One WAR with two modules | Two separately deployed services |
|---|---|---|
| Release cycles | Release one version and run one integrated deployment. | Deploy at different times if API versions and schema changes remain compatible. |
| Scaling | Add instances of the complete application and tune shared bottlenecks. | Scale catalog reads or lending writes separately if the rest of the system can support them. |
| Data ownership | Each module writes its tables. A transaction can span both changes in this database. | Each service controls its data access and commits locally. A protocol keeps reservation and loan state aligned. |
| Security | Authenticate web users and enforce permissions at application boundaries. | Also authenticate service callers, encrypt network traffic and limit each service’s credentials. |
| Observability | Follow a request and its database work in one app on a given instance. | Correlate logs, metrics and traces across calls, retries and service instances. |
| Failure handling | Exceptions can cause a local rollback. Resource exhaustion can affect both modules. | Timeouts and partial outcomes require retry rules, reconciliation and clear reporting of uncertain state. |
A timeout can hide a successful checkout
Imagine Lending sends a reservation request and the Equipment service receives it. Equipment may commit the reservation. If the response is lost or arrives after Lending’s deadline, Lending cannot tell from the timeout whether the operation succeeded. A new request treated as a fresh reservation could deliver a misleading error or produce an extra reservation for another resource. Assuming failure could strand the drill in reserve without a corresponding loan.
A service contract could give each checkout an operation ID, so retrying the same ID returns the same recorded outcome. A status endpoint could let Lending ask what happened. A durable workflow would record pending requests, reconcile uncertain outcomes, and release or expire reservations that never become loans. Both teams would agree on who can confirm, release or expire a reservation and how those transitions interact. This is a conceptual design. The downloadable WAR demonstrates the local transaction. Fowler describes how independent deployment and stronger boundaries come with distribution, consistency and operational costs. Martin Fowler, Microservice Trade-Offs
Separately deployed services can still get HTTP routing, injection, validation and local transactions from a Jakarta EE runtime or another framework. They can also use managed databases, identity providers, message brokers and telemetry services. The added work comes from integrating and operating multiple deployable components. Someone must own the remote contract, configure its security, operate its dependencies and handle failures between components.
When a modular monolith is the better fit
Suppose one team runs the workshop, changes to checkout usually touch both Catalog and Lending, and one deployment meets the workshop’s traffic and availability needs. Two services would give the team two artifacts to deploy and two runtimes to monitor. The team would still have to coordinate changes that require both services to move together.
- Keep a single transaction for a single business decision. At checkout, the workshop needs the equipment status and the loan record to agree. With one database transaction, both writes commit together or roll back together. With separate databases, a successful reservation and an interrupted loan write can leave the drill unavailable. Staff need a way to see what happened and resolve the incomplete checkout.
- Keep changing boundaries cheap. Early on, the workshop may discover that an item can be reserved in advance or that a damaged return must go through inspection. Inside one application, the team can revise both module APIs and test the entire workflow in one release. Across services, it also needs to account for old and new API versions running at the same time.
- Separate deployments only where they buy independence. If Catalog and Lending release in lockstep and checkout requires both to be healthy, cross-module changes and checkout incidents can still involve both components. The team now also has to maintain service credentials, correlate logs across processes and test failures that happen between them.
One WAR can still run on several instances, with the shared data and session setup described earlier. Keep the interfaces and architecture tests in place while one deployment serves the workshop well. Revisit the decision when you can name what needs to ship, scale or recover independently and show where the current setup gets in the way. Martin Fowler, Microservice Trade-Offs
Infrastructure overhead on an unstable data center network
In the workshop WAR, Lending calls Catalog inside the same WildFly process. WildFly manages the database connection pool and the transaction. It also provides application security and, with the appropriate configuration, facilities such as timers and messaging. In a microservice architecture, teams must explicitly decide how to supply and operate the infrastructure each service needs. A Jakarta EE runtime, a framework or a managed platform can supply many of those capabilities. The service boundary adds work of its own, such as service discovery, service-to-service authentication, and coordinating changes that span independently committed databases. WildFly 42 Admin Guide
Now imagine intermittent packet loss or latency spikes between racks in the same data center. Checkout may need a network round trip from Lending to Catalog before it can finish. Database connections, broker traffic if messaging is enabled, and background traffic such as health checks and telemetry exports can share the same network. Under degradation, some checkouts wait longer and hold connections or threads while they wait. If several layers retry the same request, they can multiply traffic and load precisely when the system is struggling. The impact can show up as slow checkouts, failed loans or an outage that spreads beyond the original fault. AWS Builders’ Library on retries and backoff · Google SRE on cascading failures
A modular monolith removes the Lending-to-Catalog network hop from that workflow. A production installation can still depend on the network for a remote database, identity provider or communication between replicas. Before adding service boundaries, test checkout under realistic packet loss and latency spikes. Compare slow checkout times, timeout rates and retry volume with the benefit you expect from independent deployment.
Use a measured reason to split
Suppose several partner workshops start using the catalog, and usage data shows partner searches repeatedly exhausting shared resources during checkout peaks. If query tuning, caching and resource controls cannot meet both workloads’ needs, independently scaling the catalog becomes a concrete benefit. A separate catalog team or a catalog release cycle regularly blocked by lending releases could strengthen the case.
Start by moving catalog reads behind a versioned service contract. The remote service can own item descriptions and expose availability with explicitly documented freshness. Lending can temporarily retain the authoritative reservation state in its own database, where it can still enforce one active checkout and save the loan in one transaction. Feed the catalog with availability updates keyed by stable item IDs. Define how updates are replayed, how duplicates are handled and how to rebuild the read view. A later move of reservation authority would need the explicit request and status protocol described above. This design choice trades immediate catalog freshness for a smaller first extraction.
6. Run the workshop
Unzip the project and open its README for Windows and Linux/macOS commands. Install JDK 21, Maven and regular WildFly 42, build with mvn clean verify, start WildFly using standalone.xml, then deploy target/workshop.war. Open http://127.0.0.1:8080/workshop/. Try a valid loan, an empty or overlong name, another loan for the same item, the simulated rollback and a return.
The lab uses the bundled ExampleDS DataSource and an in-memory H2 database. The persistence settings create and seed the schema at deployment and can erase the lab tables on redeployment. Use an isolated local server. For real workshop data, supply a persistent database, dedicated credentials, versioned migrations, backups and restores, and authorization rules for each operation. Validate transaction locking, connection pool behavior and failure recovery against the chosen database. Remove the practice failure control before production use.
What was verified
On Windows, Maven 3.9.11 built one WAR and passed both architecture tests using Temurin 21.0.13.1+2. The WAR deployed to WildFly 42.0.0.Final with standalone.xml and the bundled H2 2.4.240 database. In Chrome, the deployed Faces forms passed a successful checkout, blank and overlong name checks, rejection of a second checkout, the forced rollback with a fresh database-backed read, a successful retry and a return.
Production verification remains specific to your installation. The lab checks neither a production database and concurrent load nor identity integration, session failover, migrations, backup and restore. The two-service timeout is a design exercise.
Organize the application around who owns each decision first. The catalog owns whether the drill can leave. Lending owns the loan record. Once you can explain and test that boundary, you can weigh the benefits of moving it across a network.