Skip to main content

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

TypeExample
String"hello"
Number42, 3.14
Booleantrue, false
Object/Dict{ "key": "value" }
Array/List[1, 2, 3]
Nullnull

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

GuaranteeDescription
Single value per keyEach key holds exactly one value
PersistenceValues persist until explicitly deleted
Last-write-winsMost recent successful write determines the value
Read consistencyReads return the latest stored value

Common Mistakes

MistakeWhy It's a Problem
Using it as a databaseNo queries, no transactions, no joins
Assuming coordinated writesConcurrent writers are not synchronized
Storing critical stateNo strict consistency guarantees
Large payloadsDesigned 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 ✌️