[id='scattered-{context}']
= Scattered Caches

Scattered mode is very similar to Distribution Mode as it allows linear scaling of the cluster.
It allows single node failure by maintaining two copies of the data (as Distribution Mode with numOwners=2).
Unlike Distributed, the location of data is not fixed; while we use the same Consistent Hash algorithm
to locate the primary owner, the backup copy is stored on the node that wrote the data last time.
When the write originates on the primary owner, backup copy is stored on any other node (the exact location
of this copy is not important).

This has the advantage of single Remote Procedure Call (RPC) for any write (Distribution Mode requires one or two RPCs), but reads
have to always target the primary owner. That results in faster writes but possibly slower reads, and therefore this
mode is more suitable for write-intensive applications.

Storing multiple backup copies also results in slightly higher memory consumption. In order to remove out-of-date
backup copies, invalidation messages are broadcast in the cluster, which generates some overhead. This makes
scattered mode less performant in very big clusters (this behaviour might be optimized in the future).

When a node crashes, the primary copy may be lost. Therefore, the cluster has to reconcile the backups
and find out the last written backup copy. This process results in more network traffic during state transfer.

Since the writer of data is also a backup, even if we specify machine/rack/site ids on the transport level the cluster
cannot be resilient to more than one failure on the same machine/rack/site.

Currently it is not possible to use scattered mode in transactional cache. Asynchronous replication
is not supported either; use asynchronous Cache API instead. Functional commands are not implemented neither
but these are expected to be added soon.

The cache is configured in a similar way as the other cache modes, here is an example of declarative configuration:

[source,xml,options="nowrap",subs=attributes+]
----
include::config_examples/scattered_cache.xml[]
----

And this is how you can configure it programmatically:
[source,java]
----
include::code_examples/ScatteredCache.java[]
----

Scattered mode is not exposed in the server configuration as the server is usually accessed through the Hot Rod
protocol. The protocol automatically selects primary owner for the writes and therefore the write (in distributed
mode with two owner) requires single RPC inside the cluster, too. Therefore, scattered cache would not bring
the performance benefit.
