# Synchronization

{% hint style="info" %}
Recommended to wait for the sync bar to finish syncing before messaging.
{% endhint %}

<figure><img src="/files/bZfhKT3zZCuuWCaNz4fv" alt="Vector Messenger Add Contacts (Screenshot)"><figcaption><p>Synchronization Bar (Chat Tab)</p></figcaption></figure>

When opening Vector and loading on the Chat Tab, you will be greeted with a green flashing bar that represents your client and account syncing. It is recommended to let this process complete before sending messages, though it is not required. Messages can still be sent while Vector is syncing, but it is best to let it finish syncing to make sure you have the latest messages displayed properly.

***

## **How it Works**

The local database loads first (instant UI), then network sync fills in anything new using 2-day windows, then switches to real-time subscriptions. Background tasks keep relays healthy and profiles fresh. Below you can find more details about the Vector Syncing Process.

***

## Syncing Process

### **1. Login & Connect**

* Loads your Nostr keys, connects to all relays (trusted ones like `jskitty.cat`, `asia.vectorapp.io`, `computingcache.com`, plus `damus.io` and any custom relays you've added)

### **2. Initial Load (from local database)**

* Loads all your saved profiles, chats, and last messages from the local encrypted DB
* Preloads the last 30 days of event IDs into memory (for duplicate detection)
* Checks that any downloaded file attachments still exist on disk
* Sends all this to the frontend → **you see your chats almost instantly** (before network sync even starts)

### **3. Network Sync**

* Starts fetching **GiftWraps** (NIP-17/NIP-59 encrypted messages) from relays
* Uses a **2-day sliding window**: first grabs the last 2 days, then keeps going backward in 2-day chunks
* Each event gets unwrapped, deduplicated (2-tier: memory cache + DB check), and saved
* You see the sync progress bar during this phase
* Stops scanning backward after 5 consecutive empty windows (no more messages to find)

### **4. Real-Time Subscriptions**

* Once sync finishes, it opens **live subscriptions** on all relays for:
  * GiftWraps (DMs, files)
  * MLS Group Messages (group chats)
* New messages now arrive in real-time

### **5. Background Tasks (always running)**

* **Profile sync**: priority queue system (critical → immediate, low priority → every 24hrs)
* **Relay health checks**: every 15 seconds, tests relay responsiveness
* **Relay recovery**: every 5 seconds, reconnects any dropped relays
* When a relay reconnects, it auto-syncs the last 2 days from that relay specifically

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vector-privacy.gitbook.io/vector-privacy/vector-messenger/features/sync.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
