Skip to main content
Active Object

Intent

The Active Object design pattern provides a safe and reliable way to implement asynchronous behavior in concurrent systems. It achieves this by encapsulating tasks within objects that have their own thread and message queue. This separation keeps the main thread responsive and avoids issues like direct thread manipulation or shared state access.


iluwatarAbout 2 minConcurrencyPerformance
Caching

Intent

The caching pattern avoids expensive re-acquisition of resources by not releasing them immediately
after use. The resources retain their identity, are kept in some fast-access storage, and are
re-used to avoid having to acquire them again.

Explanation

Real world example


iluwatarAbout 4 minBehavioralPerformanceCloud distributed
Circuit Breaker

Intent

Handle costly remote service calls in such a way that the failure of a single service/component
cannot bring the whole application down, and we can reconnect to the service as soon as possible.

Explanation

Real world example

Imagine a web application that has both local files/images and remote services that are used for
fetching data. These remote services may be either healthy and responsive at times, or may become
slow and unresponsive at some point of time due to variety of reasons. So if one of the remote
services is slow or not responding successfully, our application will try to fetch response from
the remote service using multiple threads/processes, soon all of them will hang (also called
thread starvation) causing our entire web application to crash. We should be able to detect
this situation and show the user an appropriate message so that he/she can explore other parts of
the app unaffected by the remote service failure. Meanwhile, the other services that are working
normally, should keep functioning unaffected by this failure.


iluwatarAbout 5 minBehavioralPerformanceDecouplingCloud distributed
CQRS

Intent

CQRS Command Query Responsibility Segregation - Separate the query side from the command side.

Class diagram

CQRS

Applicability

Use the CQRS pattern when

  • You want to scale the queries and commands independently.
  • You want to use different data models for queries and commands. Useful when dealing with complex domains.
  • You want to use architectures like event sourcing or task based UI.

iluwatarLess than 1 minuteArchitecturalPerformanceCloud distributed
Data Locality

Intent

Accelerate memory access by arranging data to take advantage of CPU caching.

Modern CPUs have caches to speed up memory access. These can access memory adjacent to recently accessed memory much quicker. Take advantage of that to improve performance by increasing data locality keeping data in contiguous memory in the order that you process it.


iluwatarLess than 1 minuteBehavioralGame programmingPerformance
Data Transfer Object

Intent

Pass data with multiple attributes in one shot from client to server, to avoid multiple calls to
remote server.

Explanation

Real world example

We need to fetch information about customers from remote database. Instead of querying the
attributes one at a time, we use DTOs to transfer all the relevant attributes in a single shot.


iluwatarAbout 1 minArchitecturalPerformance
Dirty Flag

Also known as

  • IsDirty pattern

Intent

To avoid expensive re-acquisition of resources. The resources retain their identity, are kept in some
fast-access storage, and are re-used to avoid having to acquire them again.

Class diagram

Dirty Flag

iluwatarLess than 1 minuteBehavioralGame programmingPerformance
Double Buffer

Intent

Double buffering is a term used to describe a device that has two buffers. The usage of multiple
buffers increases the overall throughput of a device and helps prevents bottlenecks. This example
shows using double buffer pattern on graphics. It is used to show one image or frame while a separate
frame is being buffered to be shown next. This method makes animations and games look more realistic
than the same done in a single buffer mode.


iluwatarAbout 3 minBehavioralPerformanceGame programming
Double Checked Locking

Intent

Reduce the overhead of acquiring a lock by first testing the
locking criterion (the "lock hint") without actually acquiring the lock. Only
if the locking criterion check indicates that locking is required does the
actual locking logic proceed.

Class diagram


iluwatarLess than 1 minuteIdiomPerformance
Event Sourcing

Intent

Instead of storing just the current state of the data in a domain, use an append-only store to record the full series of actions taken on that data. The store acts as the system of record and can be used to materialize the domain objects. This can simplify tasks in complex domains, by avoiding the need to synchronize the data model and the business domain, while improving performance, scalability, and responsiveness. It can also provide consistency for transactional data, and maintain full audit trails and history that can enable compensating actions.


iluwatarLess than 1 minuteArchitecturalPerformanceCloud distributed
2
3
4