Key-Value Store
What is the Key-Value Store?
The RelayX Key-Value Store stores and retrieves small pieces of shared state with low latency.
Key properties:
- Values are stored under a string key
- Any client can read or write a value
- Writes overwrite previous values (last-write-wins)
- Scoped to your RelayX account
- Values persist until explicitly deleted
Not Available for iOS
The Key-Value Store is not currently available in the Swift SDK.
Initializing the Store
Before any KV operations, initialize the store from a connected client:
const kvStore = await client.initKVStore();
Writing a Value
Use put() to create or update a key:
// Store different value types
await kvStore.put("config.maxRetries", 5);
await kvStore.put("featureFlags.newUI", true);
await kvStore.put("service.metadata", { region: "ap-south-1" });
await kvStore.put("service.name", "my-service");
Key Rules
- Must be a non-empty string
- Allowed characters:
a-z,A-Z,0-9,_,-,.,=,/
Supported Value Types
| Type | Example |
|---|---|
| String | "hello" |
| Number | 42, 3.14 |
| Boolean | true, false |
| Object/Dict | { "key": "value" } |
| Array/List | [1, 2, 3] |
| Null | null |
Reading a Value
Use get() to retrieve a value by key:
const retries = await kvStore.get("config.maxRetries");
console.log(retries); // 5
const missing = await kvStore.get("nonexistent.key");
console.log(missing); // undefined or null
Deleting a Key
Use delete() to permanently remove a key:
await kvStore.delete("featureFlags.newUI");
Listing All Keys
Use keys() to get all stored keys:
const allKeys = await kvStore.keys();
console.log(allKeys); // ["config.maxRetries", "service.metadata", ...]
Good Use Cases
The Key-Value Store works best for:
- Configuration values — app settings, thresholds
- Feature flags — toggle features on/off
- Shared state — small pieces of data multiple clients need
- User preferences — per-user settings
What This Is Not
The Key-Value Store is not:
- A database (no queries, joins, or transactions)
- A coordination service (no locking)
- A history tracker (no versioning)
It stores the latest value only. Newer writes replace older ones.
Guarantees
| Guarantee | Description |
|---|---|
| Single value per key | Each key holds exactly one value |
| Persistence | Values persist until explicitly deleted |
| Last-write-wins | Most recent successful write determines the value |
| Read consistency | Reads return the latest stored value |
Common Mistakes
| Mistake | Why It's a Problem |
|---|---|
| Using it as a database | No queries, no transactions, no joins |
| Assuming coordinated writes | Concurrent writers are not synchronized |
| Storing critical state | No strict consistency guarantees |
| Large payloads | Designed for small values only |
Limitations
- No atomic operations
- No partial updates
- No conditional writes
- No history or versioning
Need Help?
Join our Discord server, post your concern & someone from our team will help you out ✌️