What a system remembers

~7 min

Open a shopping app and add something to your cart. Close the app, return tomorrow, and the item may still be there.

The application remembered what you had done.

That remembered information is an example of Concept · lights on your mapstateThe information describing a system’s current condition at a particular moment: your cart, whether you’re logged in, how far through a video you are. When engineers say something is “stateful,” they mean it carries memory that must be kept correct..

What is state?

A system’s state is the information describing its current condition at a particular moment.

Your shopping cart has state because the application needs to remember which products it currently contains, and your account has state because the system may remember whether you are logged in. A music app has state too. It remembers which song is playing and how far through it you are.

Other examples of state include:

  • The items in your cart
  • Your current account settings
  • Whether a message has been read
  • Your progress through a video
  • The current balance in a bank account
  • The score in a game

State helps a system remember what has already happened so it can respond appropriately to what happens next.

And without state, every interaction would begin as though the system had never seen you before.

Connecting state to input, processing, and output

Earlier, you learned that software commonly follows the pattern: Input → Processing → Output

State helps connect one trip through that process to the next.

When you add a product to your cart, your tap is the input, the software processes that action and updates the cart’s state, and the updated cart displayed on the screen is an output.

When you later open the application again, the software reads the saved state so it can show you what is already in your cart.

The processing step is therefore often doing two things:

  • Reading existing state
  • Changing or creating new state

This is how software remembers the past and uses it to determine what should happen next.

Temporary state and saved state

Not all state needs to last for the same amount of time.

Some state is temporary. An application may remember which menu you currently have open, for example, and that information can disappear when you close the app without causing a problem.

But other state needs to persist, meaning it must remain available after the application closes or the device restarts. Your account information, saved documents, purchases, and shopping cart may all need to be stored for later use.

The exact location can vary. State may be stored on your device, on the company’s remote systems, or in both places.

Later, you will learn how databases and other storage systems preserve this information.

What happens when state exists in more than one place?

State becomes more difficult to manage when several parts of a system hold copies of the same information.

Imagine that your phone shows three items in your cart while the company’s remote system shows only two, perhaps because you added the third item while traveling through a tunnel with no connection.

Now the system must answer several questions:

  • Which version is correct?
  • Should the phone send its update when it reconnects?
  • Should the company’s version replace the phone’s version?
  • Can the two versions be combined?
  • What happens if the item is no longer available?

Different products may answer these questions differently. But the important point is that multiple copies of the same information can become inconsistent when they are not updated at the same time.

This is one reason seemingly simple features can be difficult to build reliably.

What is a source of truth?

A Concept · lights on your mapsource of truthThe place or system treated as the authoritative version of a particular piece of information. Copies may exist everywhere for speed or convenience, but when copies disagree, the source of truth is the version the system ultimately relies on. is the place or system treated as the authoritative version of a particular piece of information.

Other copies may exist, but when there is disagreement, the source of truth is the version the system ultimately relies on.

For example, a shopping company may treat the cart stored in its central system as the source of truth, while your phone may keep a local copy so the cart loads quickly, a copy that may need to synchronize with the company’s system.

The company could also design rules that allow your phone’s newer change to update the central version. The exact behavior depends on how the product is designed.

What matters is that the team understands which system has authority and how other copies stay synchronized with it.

Why the source of truth matters

Without a clearly defined source of truth, different parts of a company may disagree about the same fact.

One system might contain one customer email address while another contains an older one, and a billing system might show one subscription status while the customer-support system shows another.

This can lead to incorrect messages, failed payments, confusing customer experiences, and difficult investigations.

That is why questions such as the following are common in technical and product conversations:

  • What is the source of truth for customer email addresses?
  • Which system owns the order status?
  • Where is the official account balance stored?

These questions are really asking: Which version should everyone trust?

State makes software personal and continuous

State is what allows a product to feel continuous from one interaction to the next.

It allows an application to remember:

  • Who you are
  • What you have done
  • What you currently have
  • What should happen next

A product without state would forget your cart, account, preferences, progress, and history whenever an interaction ended.

Managing state becomes increasingly difficult when many users, devices, and systems can change the same information, which is why databases, synchronization, transactions, and distributed systems all exist partly to help software store and manage state correctly.

You will explore those ideas later in the curriculum.

The mental model to remember

State is the information that describes a system’s current condition.

Some state is temporary, while other state must be saved so that it remains available later.

A source of truth is the authoritative place a system relies on for a particular piece of information.

When trying to understand a product, ask:

  • What does the system need to remember?
  • Where is that information stored?
  • Can copies of it exist in multiple places?
  • Which place is considered the source of truth?
Check — then the lesson continues

You change your profile photo on your laptop. Your phone shows the old photo for a minute, then catches up. What did you just witness?

▼ answer the check to continue ▼