Conceptcore
Enterprise application
Also called enterprise applications, business application, information system, enterprise software.
An enterprise application keeps a lot of persistent data, serves many users at the same time, shows the data on many screens and works with other systems.
Idea
An enterprise application is the kind of program that a business runs on: a payroll system, a booking system, an accounting system or a web shop. Martin Fowler chose the term for the systems in the book Patterns of Enterprise Application Architecture, and says that "there is no formal definition for this term".1 The catalog of the book's patterns gives a short description: "Enterprise applications are about the display, manipulation, and storage of large amounts of often complex data; together with the support or automation of business processes with that data."2 Fowler also says what they are not: "they are different from embedded systems, control systems, telecoms, or desktop productivity software."2
The name is about the kind of problem, not the size of the company. Fowler: "Enterprise applications can be large or small."1 In Fowler's view, "even small start-ups rely on software that I would call an enterprise application".1
The program below shows one of the marks of an enterprise application. Two users want the last seat on a flight. The program does not use threads or locks to protect the seat. The transaction of the database does it.
import sqlite3
db = sqlite3.connect(":memory:")
db.executescript("create table flight (id integer primary key, seats_left integer);"
"insert into flight values (7, 1);")
def book(flight_id):
# The database transaction, not the program, keeps two users from taking one seat.
with db:
cursor = db.execute("update flight set seats_left = seats_left - 1 "
"where id = ? and seats_left > 0", (flight_id,))
return "ok" if cursor.rowcount == 1 else "no seat left"
print("first user:", book(7))
print("second user:", book(7))
first user: ok
second user: no seat left
How it works
Fowler lists the characteristics that enterprise applications have in common.1 The examples of this page show each of them in a small booking system.
- Persistent data. "Enterprise applications usually have a lot of persistent data", usually in a relational database. "This data will usually be longer lasting and more valuable than the applications that process it."1 The data of a bank outlives many versions of its programs.
- Concurrent access. "This data is accessed and manipulated concurrently".1 An in-house system can have tens of users and a public web application tens of thousands.1 The developers do not usually write locks and critical regions. "Instead they build their thinking on top of transactions managed by databases or specialized transaction management tools."1
- Many screens. "Usually the same data is manipulated in different ways in different contexts."1 In the examples, an agent sees all the bookings of a flight, and a customer sees all the flights of one person.
- Batch processing. "There is also a significant amount of offline (batch) processing that is easily forgotten."1
- Integration. A new application is not alone. "Instead you'll need to integrate with other enterprise applications", by file exchange, shared databases or messaging middleware.1 In the examples, a night job writes the new bookings to a file for the system of the airline.
- Conceptual dissonance. Two systems can use one word for different things: "a customer may mean something quite different to the sales organization than it does to technical support."1
- Business logic. Business rules are not designed to be simple. "They are usually a haphazard array of strange conditions that interact in surprising ways."1
These characteristics give the subjects of the patterns. Fowler's book is about how to put the application in layers, how to organize the domain logic, how to connect that logic to a relational database, how to design a web presentation, how to distribute the application, and how to control concurrency across more than one database transaction.3
In languages
| Language | Verdict | Note |
|---|---|---|
| Python | Native | |
| C++ | Open | Not decided yet. |
| Java | Native | |
| C | Open | Not decided yet. |
| C# | Open | Not decided yet. |
| JavaScript | Open | Not decided yet. |
| TypeScript | Open | Not decided yet. |
| Go | Native | |
| Rust | Open | Not decided yet. |
| Kotlin | Open | Not decided yet. |
| SQL | Open | Not decided yet. |
| Bash | Open | Not decided yet. |
| PowerShell | Open | Not decided yet. |
| HTML | Open | Not decided yet. |
| CSS | Open | Not decided yet. |
| Regular expressions | Open | Not decided yet. |
The language matters less than the framework, because the frameworks implement many of the patterns. Fowler: "Frameworks still require you to make decisions about how to use them, and knowing the underlying patterns is essential if you are to make wise choices."3
- Java. Jakarta EE and Spring are the main platforms. The Spring documentation starts: "Spring makes it easy to create Java enterprise applications."4
- C#. The Microsoft guide to ASP.NET Core architecture says that "most non-trivial business applications benefit from some logical separation into several layers", and that "Logical layering is a common technique for improving the organization of code in enterprise software applications".5
- Python. Django gives the persistent data, the transactions and the screens. Its documentation recommends model methods as "a valuable technique for keeping business logic in one place".6
- Ruby. Fowler writes: "I would call Ruby on Rails a framework for building enterprise applications".1
The Python, Java and Go examples of this page show the same booking system. Only the Python example uses a real database.
import sqlite3
# Persistent data: the database keeps the flights and the bookings for years.
db = sqlite3.connect(":memory:")
db.executescript("""
create table flight (id integer primary key, city text, seats_left integer);
create table booking (flight_id integer, customer text, sent integer default 0);
insert into flight values (7, 'Oslo', 1);
""")
# Concurrent users: each booking is one transaction, and the update checks the seat count,
# so two users cannot both take the last seat.
def book(flight_id, customer):
with db:
cursor = db.execute(
"update flight set seats_left = seats_left - 1 where id = ? and seats_left > 0",
(flight_id,),
)
if cursor.rowcount == 0:
return "no seat left"
db.execute("insert into booking (flight_id, customer) values (?, ?)", (flight_id, customer))
return "ok"
# Many screens: each screen shows the same data in a different way.
def agent_screen(flight_id):
city, seats = db.execute("select city, seats_left from flight where id = ?", (flight_id,)).fetchone()
names = [r[0] for r in db.execute("select customer from booking where flight_id = ?", (flight_id,))]
return f"agent screen: flight {flight_id} to {city}, seats left {seats}, booked by {', '.join(names)}"
def customer_screen(customer):
rows = db.execute(
"select f.id, f.city from booking b join flight f on f.id = b.flight_id where b.customer = ?",
(customer,),
).fetchall()
return f"customer screen for {customer}: " + "; ".join(f"flight {i} to {c}" for i, c in rows)
# Batch processing and integration: a night job sends new bookings to another system as a file.
def night_batch():
with db:
rows = db.execute("select flight_id, customer from booking where sent = 0").fetchall()
db.execute("update booking set sent = 1 where sent = 0")
return "\n".join(f"{flight_id};{customer}" for flight_id, customer in rows), len(rows)
for customer in ("Ann", "Bob"):
print(f"{customer} books flight 7: {book(7, customer)}")
print(agent_screen(7))
print(customer_screen("Ann"))
text, count = night_batch()
print(f"night batch: {count} booking sent to the airline system")
print("airline file:", text)
print("second night batch:", night_batch()[1], "bookings")
Ann books flight 7: ok
Bob books flight 7: no seat left
agent screen: flight 7 to Oslo, seats left 0, booked by Ann
customer screen for Ann: flight 7 to Oslo
night batch: 1 booking sent to the airline system
airline file: 7;Ann
second night batch: 0 bookings
SQLite stands in for the database server. The with db: block is one transaction, and the update checks the seat count in the same statement, so a second booking of the last seat changes no row. The two screens read the same tables, and the night batch marks the rows that it sent, so a second run sends nothing.
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
record Flight(int id, String city) {}
static final class Booking {
final int flightId;
final String customer;
boolean sent;
Booking(int flightId, String customer) {
this.flightId = flightId;
this.customer = customer;
}
}
// The store stands in for the database. Its methods are synchronized, so each call is
// one transaction, and two users cannot both take the last seat.
static final class Store {
private final Flight flight = new Flight(7, "Oslo");
private int seatsLeft = 1;
private final List<Booking> bookings = new ArrayList<>();
synchronized String book(int flightId, String customer) {
if (flightId != flight.id() || seatsLeft == 0) return "no seat left";
seatsLeft--;
bookings.add(new Booking(flightId, customer));
return "ok";
}
// Many screens: each screen shows the same data in a different way.
synchronized String agentScreen(int flightId) {
String names = bookings.stream().filter(b -> b.flightId == flightId).map(b -> b.customer)
.collect(Collectors.joining(", "));
return "agent screen: flight " + flightId + " to " + flight.city() + ", seats left " + seatsLeft
+ ", booked by " + names;
}
synchronized String customerScreen(String customer) {
String trips = bookings.stream().filter(b -> b.customer.equals(customer))
.map(b -> "flight " + b.flightId + " to " + flight.city()).collect(Collectors.joining("; "));
return "customer screen for " + customer + ": " + trips;
}
// Batch processing and integration: a night job sends new bookings to another system as a file.
synchronized List<String> nightBatch() {
List<String> lines = new ArrayList<>();
for (Booking b : bookings) {
if (!b.sent) {
lines.add(b.flightId + ";" + b.customer);
b.sent = true;
}
}
return lines;
}
}
public static void main(String[] args) {
Store store = new Store();
for (String customer : List.of("Ann", "Bob")) {
System.out.println(customer + " books flight 7: " + store.book(7, customer));
}
System.out.println(store.agentScreen(7));
System.out.println(store.customerScreen("Ann"));
List<String> lines = store.nightBatch();
System.out.println("night batch: " + lines.size() + " booking sent to the airline system");
System.out.println("airline file: " + String.join("\n", lines));
System.out.println("second night batch: " + store.nightBatch().size() + " bookings");
}
}
Ann books flight 7: ok
Bob books flight 7: no seat left
agent screen: flight 7 to Oslo, seats left 0, booked by Ann
customer screen for Ann: flight 7 to Oslo
night batch: 1 booking sent to the airline system
airline file: 7;Ann
second night batch: 0 bookings
A Store object stands in for the database. Its methods are synchronized, so each call runs alone, as a database transaction would. A real Java application would use JDBC or JPA, and the transaction would be in the database.
package main
import (
"fmt"
"strings"
"sync"
)
type booking struct {
flightID int
customer string
sent bool
}
// Store stands in for the database. The mutex makes each method one transaction,
// so two users cannot both take the last seat.
type Store struct {
mu sync.Mutex
city map[int]string
seatsLeft map[int]int
bookings []*booking
}
func (s *Store) Book(flightID int, customer string) string {
s.mu.Lock()
defer s.mu.Unlock()
if s.seatsLeft[flightID] == 0 {
return "no seat left"
}
s.seatsLeft[flightID]--
s.bookings = append(s.bookings, &booking{flightID: flightID, customer: customer})
return "ok"
}
// Many screens: each screen shows the same data in a different way.
func (s *Store) AgentScreen(flightID int) string {
s.mu.Lock()
defer s.mu.Unlock()
var names []string
for _, b := range s.bookings {
if b.flightID == flightID {
names = append(names, b.customer)
}
}
return fmt.Sprintf("agent screen: flight %d to %s, seats left %d, booked by %s",
flightID, s.city[flightID], s.seatsLeft[flightID], strings.Join(names, ", "))
}
func (s *Store) CustomerScreen(customer string) string {
s.mu.Lock()
defer s.mu.Unlock()
var trips []string
for _, b := range s.bookings {
if b.customer == customer {
trips = append(trips, fmt.Sprintf("flight %d to %s", b.flightID, s.city[b.flightID]))
}
}
return "customer screen for " + customer + ": " + strings.Join(trips, "; ")
}
// NightBatch is batch processing and integration: it sends new bookings to another system as a file.
func (s *Store) NightBatch() []string {
s.mu.Lock()
defer s.mu.Unlock()
var lines []string
for _, b := range s.bookings {
if !b.sent {
lines = append(lines, fmt.Sprintf("%d;%s", b.flightID, b.customer))
b.sent = true
}
}
return lines
}
func main() {
store := &Store{city: map[int]string{7: "Oslo"}, seatsLeft: map[int]int{7: 1}}
for _, customer := range []string{"Ann", "Bob"} {
fmt.Printf("%s books flight 7: %s\n", customer, store.Book(7, customer))
}
fmt.Println(store.AgentScreen(7))
fmt.Println(store.CustomerScreen("Ann"))
lines := store.NightBatch()
fmt.Printf("night batch: %d booking sent to the airline system\n", len(lines))
fmt.Println("airline file:", strings.Join(lines, "\n"))
fmt.Println("second night batch:", len(store.NightBatch()), "bookings")
}
Ann books flight 7: ok
Bob books flight 7: no seat left
agent screen: flight 7 to Oslo, seats left 0, booked by Ann
customer screen for Ann: flight 7 to Oslo
night batch: 1 booking sent to the airline system
airline file: 7;Ann
second night batch: 0 bookings
A Store value stands in for the database, and its sync.Mutex makes each method run alone, as a database transaction would. A real Go application would use database/sql and the transactions of the database.
Variations and related ideas
- Enterprise software. In general use, the word enterprise means a large company. Wikipedia defines enterprise software as "computer software that has been specially developed or adapted to meet the complex requirements of larger organizations".7 Fowler's term is wider. Fowler notes that the word "has taken on connotations which don't quite fit my usage."1
- Information systems. Fowler's working title for the book was Information Systems Architecture. Fowler did not use it, because the term information systems also had connotations that did not fit.1
- Domain logic. The patterns for the business logic are Transaction script, Domain model and Table module, often with a Service layer on top.2
- Data source. The patterns that connect the logic to the database are Active Record, Data Mapper, Table Data Gateway and Row Data Gateway, with the behavioral patterns Unit of Work and Identity Map.2 The Object-relational impedance mismatch is the reason that this part is hard.
Pitfalls
- Concurrency without transactions. A check in the program, followed by a separate write, lets two users take the last seat. Put the check and the write in one database transaction, or in one statement, as the examples do.
- Forgotten batch work. Night jobs, reports and imports are part of the application. Fowler warns that the batch processing "is easily forgotten."1
- One word, two meanings. Integration can fail when two systems use the same field name with different meanings.1 Agree on the meaning of each field that crosses a system boundary.
- Logic in the screens. When each screen has its own copy of a business rule, the copies drift apart. See Transaction script and Domain model for ways to keep each rule in one place.
Cost
Fowler gives the main cost of a rich object model: "The primary cost is the awkwardness of mapping to a database, which typically results in a whole layer of O/R mapping."8 For a small enterprise application, simpler patterns cost less. Fowler notes that small systems are a challenge too, because they "need to be built quickly."1
History
Fowler wrote Patterns of Enterprise Application Architecture with Dave Rice and others, and it was published in 2002.3 The book has a short tutorial part and a reference part of about forty patterns, with code examples in Java and C#.3 Its introduction defines the term enterprise application.19 In 2014, Fowler wrote a post with the definition, and said that no other term that came to mind was better than "enterprise application".1
References
- Martin Fowler, Enterprise Application, 24 March 2014, the whole post
- Martin Fowler, Catalog of Patterns of Enterprise Application Architecture, introduction
- Martin Fowler, Patterns of Enterprise Application Architecture, book page, the book description
- Spring Framework reference, Spring Framework Overview, introduction
- Microsoft, Architect Modern Web Applications with ASP.NET Core and Azure, Common web application architectures, What is a monolithic application?; What are layers?
- Django 5.2 documentation, Models, introduction; Model methods
- Enterprise software, Wikipedia, introduction
- Martin Fowler, Anemic Domain Model, 25 November 2003, the whole post
- Martin Fowler, Patterns of Enterprise Application Architecture, Addison-Wesley, 2002, Introduction
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag XW8V70 Edit this page History Report an error Markdown