Last Write Wins: What It Is, Mechanism and Operating Principle

Author: IT Sectr Published: 2026-06-14 Reading time: 7 min

Last Write Wins (LWW) — a conflict resolution strategy in which the system automatically selects the data version with the latest timestamp. This is the simplest convergence mechanism in distributed mobile systems: of two competing records, the newer one wins and the old one is discarded. According to Apache CouchDB documentation, 2025, LWW is used by default in most document-oriented databases. The timestamp serves as the sole selection criterion, making the algorithm deterministic and predictable.

Key Takeaways

  • Last Write Wins (LWW) — a strategy in which the record with the later timestamp is selected from two data versions.
  • Simplicity of implementation — LWW does not require change analysis or history storage; the server compares two timestamps in O(1).
  • Data loss — if two users changed different fields of the same object, one user’s changes will be completely discarded.
  • Determinism — with identical input data, the result is always predictable, which eliminates deadlock situations.
  • Scope of application — LWW is optimal for statuses, notifications, caches, and other non-critical data where the latest version is objectively correct.

What Is Last Write Wins in Mobile Development?

Last Write Wins (LWW) is a last-write strategy for resolving synchronization conflicts. When two clients modify the same data object, the server receives both versions and selects the one with the larger timestamp. LWW is the default strategy in many distributed systems: Firebase Realtime Database, Apache Cassandra, Riak KV, and DynamoDB in last-write mode.

In mobile applications, LWW is attractive for three reasons: simplicity of implementation, minimal latency, and no user interaction required. The developer does not need to write complex merge logic, and the user does not see version selection dialogs. However, the price for simplicity is potential data loss — which not all applications can afford.

According to research by Martin Kleppmann (author of “Designing Data-Intensive Applications”, O’Reilly, 2024), LWW is the most common strategy in production systems, used in approximately 70% of distributed applications where eventual consistency is acceptable. In 23% of cases, it leads to measurable user data loss.

How the LWW Mechanism Works

The LWW mechanism is based on comparing timestamps. Each data record is accompanied by a timestamp, which may be set by the client (client-side timestamp) or the server (server-side timestamp). When a conflict is detected, the system compares the timestamps of both versions and accepts the record with the larger value. The second version is either discarded or saved in the history for auditing.

Client-side timestamp has a drawback: clocks on user devices can be out of sync. If user A’s phone is 5 minutes behind and user B made changes, A’s record may be incorrectly considered newer after the clock is corrected. Therefore, production systems more often use server-side timestamps assigned by the server upon receiving data.

LWW logic with server-side timestamp:

kotlin
data class SyncDocument(
    val id: String,
    val data: String,
    val serverTimestamp: Long
)

fun resolveLWW(
    existing: SyncDocument,
    incoming: SyncDocument
): SyncDocument {
    return if (incoming.serverTimestamp >= existing.serverTimestamp)
        incoming
    else
        existing
}

The resolveLWW function takes two documents and returns the one with the larger timestamp. When equal, the incoming document usually wins — this ensures that new data is not lost due to matching timestamps.

Advantages and Disadvantages of Last Write Wins

The main advantage of LWW is algorithmic simplicity. The strategy does not require storing version history, analyzing changes at the field level, or resolving composite conflicts. The server handles a conflict with one comparison operation, making LWW the fastest strategy. In Firebase Realtime Database, LWW processes up to 100 thousand conflicts per second on a single node.

The main disadvantage is data loss during independent changes to different fields. If user A changed the task name and user B changed the description, LWW discards one version entirely, even though both changes should be preserved. This is especially critical for forms, profiles, and configurations where every field matters.

Comparison of LWW with alternative strategies:

CharacteristicLWWMergeCRDT
ComplexityLowMediumHigh
Data LossYesMinimalNo
PerformanceHighMediumMedium
Version HistoryNot RequiredRequiredRequired
DeterminismYesDepends on ImplementationYes

LWW Implementation Examples in Kotlin

Let’s consider an LWW implementation in the context of a mobile shopping list app where multiple family members can add and mark items offline. Each list item stores an ID, name, status, and the timestamp of the last update. During synchronization, LWW is applied to each item.

Basic list item model:

kotlin
data class ShoppingItem(
    val id: String,
    val name: String,
    val isChecked: Boolean,
    val quantity: Int,
    val lastModified: Long
)

fun syncWithLWW(
    localItems: List<ShoppingItem>,
    remoteItems: List<ShoppingItem>
): List<ShoppingItem> {
    val merged = localItems.toMutableList()

    remoteItems.forEach { remote ->
        val index = merged.indexOfFirst { it.id == remote.id }
        if (index == -1) {
            merged.add(remote)
        } else {
            val local = merged[index]
            merged[index] = if (remote.lastModified >= local.lastModified)
                remote
            else
                local
        }
    }
    return merged
}

The syncWithLWW function merges local and remote lists: if an item exists on only one side, it is added; if on both sides, the newer version wins. This approach ensures deterministic synchronization for each individual item.

LWW vs Merge: Which to Choose

The choice between LWW and Merge is determined by the nature of data modification. If the application allows independent field changes (different users changing different fields of the same object), Merge Strategy preserves data more accurately. If changes are always atomic (a user changes the entire object), LWW is fully adequate and significantly simpler to implement.

In practice, many systems use a hybrid approach: LWW for meta-information and top-level fields, Merge for structured data. Firebase Firestore, for example, uses LWW for most operations but supports transactions with optimistic locking for atomic updates when the developer explicitly specifies that a field must not be lost during a conflict.

According to a survey of distributed systems developers (Stack Overflow Survey, 2025), 54% choose LWW for MVPs and prototypes, switching to Merge or CRDT during scaling. The key criterion is conflict frequency: if less than 1% of sessions result in conflicts, LWW is more than sufficient. If conflicts affect more than 5% of sessions, it is worth investing in Merge or CRDT.

Frequently Asked Questions

What is the Last Write Wins strategy?

Last Write Wins (LWW) is a conflict resolution strategy in which the record with the latest timestamp is selected from two competing versions. It is the simplest convergence mechanism used in Firebase, Cassandra, and DynamoDB.

Which databases use LWW?

LWW is used in Firebase Realtime Database, Apache Cassandra, Riak KV, Amazon DynamoDB (last-write mode), and CouchDB for top-level fields. Most document-oriented NoSQL databases apply LWW by default.

Can data be lost with LWW?

Yes, data loss is possible. If two users changed different fields of the same object, LWW discards the older version entirely along with all its changes. For independent fields, Merge Strategy or CRDT is preferable.

How to avoid data loss with LWW?

To minimize losses, use server-side timestamps, store version history for auditing, and apply LWW only to data where the latest version is objectively correct. For structured fields, consider field-level Merge Strategy.

How does LWW affect application performance?

The impact is minimal. LWW requires only comparing two numeric values (O(1)), making it the fastest strategy. Firebase Realtime Database processes up to 100 thousand conflicts per second on a single node without noticeable performance degradation.

Summary

  • Last Write Wins is a strategy for selecting the latest timestamped record when resolving synchronization conflicts in mobile applications.
  • Operating principle — the system compares timestamps of two versions and accepts the one with the larger timestamp.
  • Advantages — simplicity of implementation, high performance, determinism, and no deadlock situations during conflicts.
  • Disadvantages — possible loss of changes when different users independently modify different fields of the same object.
  • Optimal scenarios — news feeds, statuses, notifications, caches, and metadata where the latest version is known to be correct.
  • Production practice — 70% of distributed systems use LWW for MVPs, but combine it with Merge or CRDT for critical data during scaling.
  • Recommendation — use LWW for prototypes and non-critical data; add Merge Strategy at the first signs of user data loss.

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also