Session Facade, Message Facade, Composite View
Session Facade Pattern
The Session Facade is a JEE Business Tier Pattern. It provides a coarse-grained interface to a set of fine-grained external services. Instead of the client making multiple network calls to multiple external services, the client makes ONE call to the Session Facade, which internally coordinates all the fine-grained calls on the server side.
One line: One dummy external comp that sits in front of multiple real external comps, reducing network round trips from the client.
Problem: Multiple Network Round Trips
Here BusinessDelegate comp of Client App is having multiple round trips with multiple external comps which leads to performance issues (problem).
Solution: Session Facade Aggregates Calls
Implementation
// Session Facade interface
public interface IStockFacade {
StockDetailsDTO getCompleteStockInfo(String stockName);
}
// Session Facade implementation: aggregates 3 services
public class StockFacadeImpl implements IStockFacade {
private final IGetStockId stockIdService;
private final IGetStockValue stockValueService;
private final IGetStockFutureValue futureService;
public StockFacadeImpl() {
// All services are local to the Facade (same server)
this.stockIdService = new GetStockIdImpl();
this.stockValueService = new GetStockValueImpl();
this.futureService = new GetStockFutureValueImpl();
}
@Override
public StockDetailsDTO getCompleteStockInfo(String stockName) {
// 3 internal calls, 0 extra network round trips
int id = stockIdService.getStockId(stockName);
double value = stockValueService.getStockValue(id);
double future = futureService.getFutureValue(id);
return new StockDetailsDTO(stockName, id, value, future);
}
}
// Client side: ONE call instead of THREE
StockDetailsDTO result = facade.getCompleteStockInfo("Reliance");
- All four comps (SessionFacade + 3 external services) should be developed as Distributed comps either as WebService comp or as EJB comp. For simplification, we are developing ordinary Java classes implementing Java interfaces.
- The Session Facade and all external comps it wraps must be placed in the same environment/server so internal calls are local (no network overhead).
- The Session Facade provides a coarse-grained interface (one method that does everything) instead of multiple fine-grained calls.
Message Facade Pattern
The Message Facade is a JEE Business Tier Pattern. It is similar to Session Facade but uses asynchronous communication instead of synchronous. The client sends a message to the Message Facade and does not wait for a response. The Facade processes the request in the background using messaging systems like JMS (Java Message Service).
One line: An asynchronous version of Session Facade that uses message queues for non-blocking communication.
Synchronous vs Asynchronous Communication
| Aspect | Synchronous (Session Facade) | Asynchronous (Message Facade) |
|---|---|---|
| Client behavior | Client sends request and waits (blocked) until response is received | Client sends message and continues immediately (non-blocking) |
| Response | Immediate response in same call | Response delivered later via callback, polling, or notification |
| Technology | RMI, EJB Session Beans, REST (default) | JMS, Kafka, RabbitMQ, SQS |
| Use when | Client needs the result immediately | Client does not need immediate result |
| Examples | Stock price lookup, balance check | Email sending, report generation, order processing |
When to use Message Facade
- If the client does not need the result immediately (e.g., sending email, generating PDF report)
- If the processing takes a long time (e.g., data migration, batch processing)
- If the system needs to handle spikes in traffic (message queue acts as buffer)
- If the external service may be temporarily unavailable (messages are persisted in queue)
// Message Facade: sends message to JMS queue
public class OrderMessageFacade {
public void submitOrder(OrderDTO order) {
// Create JMS message
// Send to "orders" queue
// Client is NOT blocked - returns immediately
jmsTemplate.convertAndSend("orders-queue", order);
System.out.println("Order submitted to queue. Processing async.");
}
}
// Message Listener (processes asynchronously)
@JmsListener(destination = "orders-queue")
public void processOrder(OrderDTO order) {
// This runs in a separate thread, later
orderService.process(order);
notificationService.sendConfirmation(order);
}
| Aspect | Session Facade | Message Facade |
|---|---|---|
| Communication | Synchronous (request-response) | Asynchronous (fire-and-forget) |
| Client blocking | Yes, client waits | No, client continues |
| Technology | EJB Session Bean, REST API | JMS, MDB (Message Driven Bean), Kafka |
| Error handling | Immediate exception to client | Dead letter queue, retry mechanism |
| Use case | Real-time data (stock price, balance) | Background tasks (email, report, notification) |
Note: "QUEUE" concept in messaging is used in JEE where sent message is consumed by one and only one receiver. In "TOPIC" concept, the message published by producer gets delivered to all the subscribers. This follows the publish-subscribe model.
JMS implementations and modern equivalents
- ActiveMQ, RabbitMQ (JMS implementations)
- Apache Kafka (distributed streaming, high throughput)
- AWS SQS/SNS (cloud-native message service)
- Spring JMS, Spring AMQP, Spring Cloud Stream (framework support)
Composite View Pattern
The Composite View is a JEE Presentation Tier Pattern. A view that contains presentation logic having ability to generate views for each page independently, instead of the entire page. If the view logic is scattered in individual views, then those sub-views become a part of a larger composite view.
One line: Break a complex page into reusable sub-views (header, footer, sidebar, content) and compose them together dynamically.
JSP - JavaServer Pages: each view comp is a separate JSP file.
angular/html - PA (pagination applied) to a single column of the DB table.
Composite/PV - PA (pagination applied) to multiple columns from multiple sections from the table together.
Problem: Monolithic Views
Solution: Composite View with Includes
View Layout Types
| # | Layout | Description |
|---|---|---|
| 1 | Basic layout | Header + Body + Footer (3 regions) |
| 2 | Classic layout | Header + Left sidebar + Body + Footer |
| 3 | Menu layout | Header + Body + Right sidebar + Footer |
| 4 | Full classic layout | Header + Left sidebar + Body + Right sidebar + Footer |
| 5 | Divide layout | Header + multiple equal columns + Footer |
// main.jsp using Composite View pattern
<%-- Header: reusable across all pages --%>
<jsp:include page="header.jsp" />
<div class="layout">
<%-- Sidebar: reusable navigation --%>
<jsp:include page="sidebar.jsp" />
<%-- Main content: page-specific --%>
<div class="content">
<jsp:include page="${contentPage}" />
</div>
</div>
<%-- Footer: reusable across all pages --%>
<jsp:include page="footer.jsp" />
- Apache Tiles: Framework for Composite View in JEE. Define layouts with reusable regions. Each page fills in only the content region.
- Thymeleaf Layouts: Template inheritance with
th:fragmentandth:replace. - JSF Facelets: Template composition with
ui:composition,ui:define,ui:insert. - React/Next.js: Layout components that wrap page-specific content. This is exactly what our javabypankaj v2 does with
layout.tsxwrapping TopBar + content + Footer. - Note: The Tiles framework will also work with Struts or JSF framework's based servlets into frontend web/view patterns.
Each portion of web page that contains static content is called a tile. If the application has multiple pages which contains/need same set of tiles (like the Styles and Layout), tiles pools to avoid re-development/duplication of tiles.
Comparison Table
| Aspect | Session Facade | Message Facade | Composite View |
|---|---|---|---|
| Tier | Business | Business | Presentation |
| Purpose | Aggregate multiple services into one coarse-grained call | Async version of Session Facade using message queues | Compose reusable view fragments into pages |
| Communication | Synchronous | Asynchronous | N/A (view composition) |
| Reduces | Network round trips | Client blocking time | View code duplication |
| Modern equivalent | API Gateway, GraphQL | Kafka, RabbitMQ, SQS | React layouts, Thymeleaf templates |
Session Facade, Message Facade, and Composite View Patterns
Session Facade Pattern
The Session Facade is a JEE Business Tier Pattern. It provides a coarse-grained interface to a set of fine-grained external services. Instead of the client making multiple network calls to multiple external services, the client makes ONE call to the Session Facade, which internally coordinates all the fine-grained calls on the server side.
One line: One dummy external comp that sits in front of multiple real external comps, reducing network round trips from the client.
Problem: Multiple Network Round Trips
Here BusinessDelegate comp of Client App is having multiple round trips with multiple external comps which leads to performance issues (problem).
Solution: Session Facade Aggregates Calls
Implementation
// Session Facade interface
public interface IStockFacade {
StockDetailsDTO getCompleteStockInfo(String stockName);
}
// Session Facade implementation: aggregates 3 services
public class StockFacadeImpl implements IStockFacade {
private final IGetStockId stockIdService;
private final IGetStockValue stockValueService;
private final IGetStockFutureValue futureService;
public StockFacadeImpl() {
// All services are local to the Facade (same server)
this.stockIdService = new GetStockIdImpl();
this.stockValueService = new GetStockValueImpl();
this.futureService = new GetStockFutureValueImpl();
}
@Override
public StockDetailsDTO getCompleteStockInfo(String stockName) {
// 3 internal calls, 0 extra network round trips
int id = stockIdService.getStockId(stockName);
double value = stockValueService.getStockValue(id);
double future = futureService.getFutureValue(id);
return new StockDetailsDTO(stockName, id, value, future);
}
}
// Client side: ONE call instead of THREE
StockDetailsDTO result = facade.getCompleteStockInfo("Reliance");
- All four comps (SessionFacade + 3 external services) should be developed as Distributed comps either as WebService comp or as EJB comp. For simplification, we are developing ordinary Java classes implementing Java interfaces.
- The Session Facade and all external comps it wraps must be placed in the same environment/server so internal calls are local (no network overhead).
- The Session Facade provides a coarse-grained interface (one method that does everything) instead of multiple fine-grained calls.
Message Facade Pattern
The Message Facade is a JEE Business Tier Pattern. It is similar to Session Facade but uses asynchronous communication instead of synchronous. The client sends a message to the Message Facade and does not wait for a response. The Facade processes the request in the background using messaging systems like JMS (Java Message Service).
One line: An asynchronous version of Session Facade that uses message queues for non-blocking communication.
Synchronous vs Asynchronous Communication
| Aspect | Synchronous (Session Facade) | Asynchronous (Message Facade) |
|---|---|---|
| Client behavior | Client sends request and waits (blocked) until response is received | Client sends message and continues immediately (non-blocking) |
| Response | Immediate response in same call | Response delivered later via callback, polling, or notification |
| Technology | RMI, EJB Session Beans, REST (default) | JMS, Kafka, RabbitMQ, SQS |
| Use when | Client needs the result immediately | Client does not need immediate result |
| Examples | Stock price lookup, balance check | Email sending, report generation, order processing |
When to use Message Facade
- If the client does not need the result immediately (e.g., sending email, generating PDF report)
- If the processing takes a long time (e.g., data migration, batch processing)
- If the system needs to handle spikes in traffic (message queue acts as buffer)
- If the external service may be temporarily unavailable (messages are persisted in queue)
// Message Facade: sends message to JMS queue
public class OrderMessageFacade {
public void submitOrder(OrderDTO order) {
// Create JMS message
// Send to "orders" queue
// Client is NOT blocked - returns immediately
jmsTemplate.convertAndSend("orders-queue", order);
System.out.println("Order submitted to queue. Processing async.");
}
}
// Message Listener (processes asynchronously)
@JmsListener(destination = "orders-queue")
public void processOrder(OrderDTO order) {
// This runs in a separate thread, later
orderService.process(order);
notificationService.sendConfirmation(order);
}
| Aspect | Session Facade | Message Facade |
|---|---|---|
| Communication | Synchronous (request-response) | Asynchronous (fire-and-forget) |
| Client blocking | Yes, client waits | No, client continues |
| Technology | EJB Session Bean, REST API | JMS, MDB (Message Driven Bean), Kafka |
| Error handling | Immediate exception to client | Dead letter queue, retry mechanism |
| Use case | Real-time data (stock price, balance) | Background tasks (email, report, notification) |
Note: "QUEUE" concept in messaging is used in JEE where sent message is consumed by one and only one receiver. In "TOPIC" concept, the message published by producer gets delivered to all the subscribers. This follows the publish-subscribe model.
JMS implementations and modern equivalents
- ActiveMQ, RabbitMQ (JMS implementations)
- Apache Kafka (distributed streaming, high throughput)
- AWS SQS/SNS (cloud-native message service)
- Spring JMS, Spring AMQP, Spring Cloud Stream (framework support)
Composite View Pattern
The Composite View is a JEE Presentation Tier Pattern. A view that contains presentation logic having ability to generate views for each page independently, instead of the entire page. If the view logic is scattered in individual views, then those sub-views become a part of a larger composite view.
One line: Break a complex page into reusable sub-views (header, footer, sidebar, content) and compose them together dynamically.
JSP - JavaServer Pages: each view comp is a separate JSP file.
angular/html - PA (pagination applied) to a single column of the DB table.
Composite/PV - PA (pagination applied) to multiple columns from multiple sections from the table together.
Problem: Monolithic Views
Solution: Composite View with Includes
View Layout Types
| # | Layout | Description |
|---|---|---|
| 1 | Basic layout | Header + Body + Footer (3 regions) |
| 2 | Classic layout | Header + Left sidebar + Body + Footer |
| 3 | Menu layout | Header + Body + Right sidebar + Footer |
| 4 | Full classic layout | Header + Left sidebar + Body + Right sidebar + Footer |
| 5 | Divide layout | Header + multiple equal columns + Footer |
// main.jsp using Composite View pattern
<%-- Header: reusable across all pages --%>
<jsp:include page="header.jsp" />
<div class="layout">
<%-- Sidebar: reusable navigation --%>
<jsp:include page="sidebar.jsp" />
<%-- Main content: page-specific --%>
<div class="content">
<jsp:include page="${contentPage}" />
</div>
</div>
<%-- Footer: reusable across all pages --%>
<jsp:include page="footer.jsp" />
- Apache Tiles: Framework for Composite View in JEE. Define layouts with reusable regions. Each page fills in only the content region.
- Thymeleaf Layouts: Template inheritance with
th:fragmentandth:replace. - JSF Facelets: Template composition with
ui:composition,ui:define,ui:insert. - React/Next.js: Layout components that wrap page-specific content. This is exactly what our javabypankaj v2 does with
layout.tsxwrapping TopBar + content + Footer. - Note: The Tiles framework will also work with Struts or JSF framework's based servlets into frontend web/view patterns.
Each portion of web page that contains static content is called a tile. If the application has multiple pages which contains/need same set of tiles (like the Styles and Layout), tiles pools to avoid re-development/duplication of tiles.
Comparison Table
| Aspect | Session Facade | Message Facade | Composite View |
|---|---|---|---|
| Tier | Business | Business | Presentation |
| Purpose | Aggregate multiple services into one coarse-grained call | Async version of Session Facade using message queues | Compose reusable view fragments into pages |
| Communication | Synchronous | Asynchronous | N/A (view composition) |
| Reduces | Network round trips | Client blocking time | View code duplication |
| Modern equivalent | API Gateway, GraphQL | Kafka, RabbitMQ, SQS | React layouts, Thymeleaf templates |