# Analyzing Business Domains
> **In one sentence:** you can't design good software for a business you don't understand, so
> start by mapping what the company does and where it actually competes.

It's tempting to treat this chapter as "business stuff, not my job". It isn't. The software is the
answer to a business problem. If you misread the problem, even clean code is aimed at the wrong
target.

## Business domains and subdomains

A **business domain** is the company's main line of work, the thing customers pay it for. A
delivery company's domain is moving parcels. A coffee chain's domain is selling coffee. Large
companies often work in several domains at once (think of a retailer that also sells cloud
hosting), and a company's domains can shift completely over its lifetime.

A **subdomain** is one smaller piece of activity that the business needs in order to operate.
Selling coffee also means picking store locations, hiring and scheduling staff, buying beans and
keeping the books. No single subdomain makes the company successful, but take one away and the
whole thing wobbles.

## Types of subdomains

Not every subdomain is worth the same to the business. DDD puts them in three groups.

### Core subdomains

What the company does **differently and better** than its competitors. This is where the
competitive advantage comes from: a smarter pricing engine, a better matching algorithm, a
cheaper way to run operations.

- They are **complex**. If they were easy to build, competitors would copy them quickly.
- They are **volatile**. The company keeps experimenting and improving them to stay ahead.
- They are **not always technical**. For a handmade-furniture brand, the core is the furniture
  design. The online store that sells it is not.

> **Naming note:** some people say *core domain*. These notes stick with *core subdomain*, because
> it is a subdomain and subdomains can change type over time.

### Generic subdomains

Activities that **every company does the same way**: sign-in and permissions, encryption, payroll,
accounting. They can be hard to build, but they are already solved, and doing them "your own way"
gains you nothing. Buy a product or use an open-source one.

### Supporting subdomains

Things the business **needs but doesn't compete on**, and that are **simple**. They're usually
data-entry screens, basic CRUD or simple ETL jobs. Nothing ready-made fits them exactly, so you
build them yourself, but cheaply.

### Side-by-side comparison

| | Core | Generic | Supporting |
|---|---|---|---|
| Competitive edge | Yes | No | No |
| Business-logic complexity | High | High | Low |
| How often it changes | Often | Rarely (patches, upgrades) | Rarely |
| How to get it | Build in-house with your best people | Buy or adopt | Build simply, or outsource |
| Nature of the problem | Interesting | Solved | Obvious |

**Rules of thumb for telling them apart**

- **Core or supporting?** Could the capability be sold as a separate business? If yes, it's
  probably core.
- **Supporting or generic?** Is it cheaper to write a quick version yourself than to integrate a
  product? If yes, it's supporting.
- **Look at the logic you'll have to write.** If it's mostly forms and tables, it's supporting. If
  it's full of rules, algorithms and invariants, it's likely core.

**Why it matters for design:** each type gets a different strategy. Put your strongest engineers
and best practices on core subdomains. Don't spend effort reinventing generic ones. Keep
supporting ones simple, or outsource them, which also makes them good projects for growing junior
engineers.

## Identifying subdomain boundaries

Nobody hands you the list of subdomains. Executives rarely think in these terms, so you have to
work it out.

1. **Start with the org chart.** Departments such as warehouse, support or finance are a first rough cut.
2. **Distill.** Break each rough area into its parts. A support department might turn out to be a
   ticketing tool (generic), a phone system (generic), shift planning (supporting) and a clever
   way of routing tickets to the best-suited agent (core). That last item would stay hidden if you
   stopped at "support".
3. **Know when to stop.** A subdomain is roughly a group of **closely related use cases** that
   share the same actors and the same data. Once you reach that level, stop.
4. **Spend the effort where it pays.** Distill core subdomains carefully. For generic and
   supporting ones, stop once splitting further doesn't change any decision.
5. **Leave out what isn't software.** Some business strengths, like a designer's taste, have
   nothing to do with the system. Note them and move on.

## Worked examples

**A concert-ticket app.** It recommends nearby shows based on users' music and social activity,
and it protects their privacy.
- *Core:* the recommendation engine, data anonymization and the app experience.
- *Generic:* encryption, accounting, payment clearing and authentication.
- *Supporting:* connectors to streaming and social platforms, and a "shows I've been to" log.
- *Decisions:* build the core in-house with care, buy the generic pieces, and outsource the supporting ones.

**An on-demand bus service.** Buses change their routes in real time to pick up riders.
- *Core:* the routing algorithm (a hard optimization problem tuned to business goals such as
  faster pickups), ride-data analysis, the rider and driver apps, and fleet health.
- *Generic:* live traffic feeds, accounting, billing and authorization.
- *Supporting:* managing promo codes and discounts.

## Domain experts

**Domain experts** are the people who really know how the business works, the source of the
knowledge we turn into software. They are *not* the analysts or engineers who translate it. In
practice they're the people who set the requirements or the people who use the system day to day.
Some know the whole business; others know one subdomain deeply.

## Check yourself

1. Which subdomain types give no competitive advantage?
2. Where would you expect competitors to use the exact same solution?
3. Which type changes most often, and why?
4. Pick a product you use. Name one core, one generic and one supporting subdomain.

<details><summary>Answers</summary>

1. Generic and supporting.
2. Generic.
3. Core, because the company keeps refining it to stay ahead.
4. Your call. Check it against the rules of thumb above.

</details>
