k_yrs_go is a dedicated database server designed for YJS documents, leveraging PostgreSQL and Redis for optimal performance. By utilizing binary Redis queues for I/O buffering and efficient update management, it delivers impressive write latencies, ensuring seamless real-time collaboration for applications relying on collaborative data structures.
k_yrs_go is an efficient database server specifically designed for managing YJS documents. This project utilizes the power of Postgres and Redis to provide a robust backend solution for real-time collaborative applications.
High Performance: k_yrs_go leverages binary Redis queues as I/O buffers for YJS document updates, ensuring low latency and high throughput. The system shows average write latencies of around 1 millisecond, making it suitable for applications that require quick data updates.
Efficient Data Storage: The following SQL schema is utilized to store updates:
CREATE TABLE IF NOT EXISTS k_yrs_go_yupdates_store (
id TEXT PRIMARY KEY,
doc_id TEXT NOT NULL,
data BYTEA NOT NULL
);
CREATE INDEX IF NOT EXISTS k_yrs_go_yupdates_store_doc_id_idx ON k_yrs_go_yupdates_store (doc_id);
Easy Integration: Integrating k_yrs_go into applications is straightforward. Below is a code snippet demonstrating how to write and read updates using the server:
import axios from 'axios';
const api = axios.create({ baseURL: env.SERVER_URL });
const docId = uuid();
const ydoc = new Y.Doc();
// WRITE
ydoc.on('update', async (update: Uint8Array) => {
await api.post<Uint8Array>(`/docs/${docId}/updates`, update, {headers: {'Content-Type': 'application/octet-stream'}});
});
// READ
const response = await api.get<ArrayBuffer>(`/docs/${docId}/updates`, { responseType: 'arraybuffer' });
const update = new Uint8Array(response.data);
const ydoc2 = new Y.Doc();
Y.applyUpdate(ydoc2, update);
Benchmarks demonstrate the efficiency of k_yrs_go in handling updates. A compaction test ensures that the database remains optimized, with the number of rows per document capped at specified limits to prevent excessive growth:
```typescript
const countRes = await db('k_yrs_go_yupdates_store').where('doc_id', docId).count('id');
expect(rowsInDB).to.lessThanOrEqual(100);
```
The setup process is efficient. Developers are guided through the installation of necessary tools such as Docker and Node.js. Subsequently, running the server in development mode is achieved with:
```bash
turbo run dev
```
Configurations can be easily customized in the file server/.env and tests can be run thereafter to ensure stability. Specific environmental variables like SERVER_URL, PG_URL, and REDIS_URL can be adapted to fit any desired infrastructure requirements.
k_yrs_go is designed to be used alongside the yjs-scalable-ws-backend, expanding its functionality and scalability in real-time applications.
No comments yet.
Sign in to be the first to comment.