DEV Community

Saras Growth Space
Saras Growth Space

Posted on

LLD Domain Modeling: Entities (Objects That Have Identity and Lifecycle)

In the previous post, we learned that Domain Modeling is not about classes.

It is about understanding:

  • business behavior
  • business rules
  • ownership
  • lifecycle
  • correctness

Now we begin with the most fundamental building block of any domain model:

Entities

Almost every real system revolves around entities.

Orders.

Bookings.

Rides.

Payments.

Users.

Understanding entities correctly is one of the biggest differences between beginner and strong LLD thinking.


The Simplest Definition

An Entity is:

an object that has a unique identity and must be tracked over time.

The important phrase is:

tracked over time
Enter fullscreen mode Exit fullscreen mode

Because identity is what makes an entity special.


Example: An Order

Imagine an e-commerce system.

A customer places an order.

Order #123
Enter fullscreen mode Exit fullscreen mode

Today:

CREATED
Enter fullscreen mode Exit fullscreen mode

Tomorrow:

PAID
Enter fullscreen mode Exit fullscreen mode

Later:

SHIPPED
Enter fullscreen mode Exit fullscreen mode

Then:

DELIVERED
Enter fullscreen mode Exit fullscreen mode

Notice something important.

Many attributes changed:

  • status
  • shipment information
  • timestamps

But it is still:

Order #123
Enter fullscreen mode Exit fullscreen mode

The identity remains the same.

That is why Order is an Entity.


Identity Is More Important Than Data

Beginners often focus on fields:

Order {
    id
    amount
    status
}
Enter fullscreen mode Exit fullscreen mode

But entities are not defined by fields.

They are defined by identity.

Even if all fields change:

Amount changes
Status changes
Address changes
Enter fullscreen mode Exit fullscreen mode

The business still considers it the same Order.

Identity survives change.


Real-Life Analogy

Think about a person.

You may change:

  • hairstyle
  • phone number
  • address
  • job

But you remain the same individual.

Why?

Because your identity is independent of those attributes.

Entities behave similarly.


Entity = Continuity Through Time

This is one of the most important mental models.

Entities represent:

continuity through change.

Example:

Ride Sharing System

Ride #567
Enter fullscreen mode Exit fullscreen mode

Initially:

REQUESTED
Enter fullscreen mode Exit fullscreen mode

Then:

DRIVER_ASSIGNED
Enter fullscreen mode Exit fullscreen mode

Then:

IN_PROGRESS
Enter fullscreen mode Exit fullscreen mode

Then:

COMPLETED
Enter fullscreen mode Exit fullscreen mode

The ride evolves.

But it remains the same ride.

That continuity is what makes it an entity.


How to Identify Entities

Ask this question:

Does the business care about this object's identity?

If yes, it is probably an entity.

Examples:

User

Business tracks specific user.

Entity.


Order

Business tracks specific order.

Entity.


Booking

Business tracks specific booking.

Entity.


Ride

Business tracks specific ride.

Entity.


Payment

Business tracks specific payment.

Entity.


Another Important Question

Ask:

If two objects contain exactly the same data, are they still different?

Example:

Order #101
Amount: ₹500

Order #102
Amount: ₹500
Enter fullscreen mode Exit fullscreen mode

Same amount.

Same fields.

Still different orders.

Therefore:

Entity.


Entity Lifecycle Matters

Entities rarely stay static.

They evolve.

Example:

Booking

CREATED
→ CONFIRMED
→ CANCELLED
Enter fullscreen mode Exit fullscreen mode

Order

CREATED
→ PAID
→ SHIPPED
→ DELIVERED
Enter fullscreen mode Exit fullscreen mode

Ride

REQUESTED
→ ASSIGNED
→ STARTED
→ COMPLETED
Enter fullscreen mode Exit fullscreen mode

This lifecycle is often more important than the fields themselves.


Entities Protect Business Meaning

Consider a banking system.

Account balance changes constantly.

₹10,000
₹15,000
₹8,000
₹25,000
Enter fullscreen mode Exit fullscreen mode

The amount changes.

But the account remains the same account.

The business tracks:

Account #A123
Enter fullscreen mode Exit fullscreen mode

not merely its current balance.

Identity carries business meaning.


Common Beginner Mistake

Many developers think:

Every noun becomes an entity.

Wrong.

Example:

Address
Money
Coordinates
Distance
Enter fullscreen mode Exit fullscreen mode

These are important.

But the business usually does not track their identity.

They describe something else.

These often become Value Objects.

We will cover them in the next post.


Entity Responsibilities

A strong entity is not merely a data holder.

Bad design:

Order {
    id
    status
    amount
}
Enter fullscreen mode Exit fullscreen mode

Good design:

Order {
    pay()
    cancel()
    ship()
}
Enter fullscreen mode Exit fullscreen mode

Why?

Because the entity owns its lifecycle.

Business rules should stay close to the entity whenever possible.


Weak LLD Thinking

Entity = Database Row
Enter fullscreen mode Exit fullscreen mode

Strong LLD Thinking

Entity = Business Object With Identity and Lifecycle
Enter fullscreen mode Exit fullscreen mode

This small mindset shift changes the quality of your design dramatically.


Examples of Entities Across Systems

Ride Sharing

  • Rider
  • Driver
  • Ride

BookMyShow

  • Show
  • Booking

E-Commerce

  • User
  • Cart
  • Order

Banking

  • Customer
  • Account
  • Transaction

Food Delivery

  • Order
  • Restaurant
  • Delivery Partner

All of them have one thing in common:

the business cares about who they are, not just what data they contain.


The Most Important Insight

Fields can change.

State can change.

Behavior can change.

But identity remains.

That identity is what turns an ordinary object into an Entity.

And once you start recognizing entities correctly, domain models become much easier to design.


One-Line Takeaway

An Entity is a business object whose identity matters more than its current data, allowing it to be tracked consistently throughout its lifecycle.

Top comments (0)