{"id":29027022,"url":"https://github.com/sergij14/real-time-editor-app","last_synced_at":"2026-05-07T02:34:07.300Z","repository":{"id":296458553,"uuid":"990938144","full_name":"sergij14/real-time-editor-app","owner":"sergij14","description":"Real-time collaborative text editor built using Node.js, Socket.IO, and Quill.js, with storage in Redis and containerized using Docker for deployment/local development. The app allows multiple users to simultaneously edit the same document with instant synchronization across clients.","archived":false,"fork":false,"pushed_at":"2025-06-06T20:52:03.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-26T06:02:04.805Z","etag":null,"topics":["nodejs","reactjs","socket-io"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sergij14.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-26T22:03:35.000Z","updated_at":"2025-06-06T20:52:05.000Z","dependencies_parsed_at":"2025-05-31T07:06:23.775Z","dependency_job_id":"b9fa1d74-e0b2-4d68-8422-3e06ec24874e","html_url":"https://github.com/sergij14/real-time-editor-app","commit_stats":null,"previous_names":["sergij14/real-time-editor-app"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sergij14/real-time-editor-app","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergij14%2Freal-time-editor-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergij14%2Freal-time-editor-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergij14%2Freal-time-editor-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergij14%2Freal-time-editor-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sergij14","download_url":"https://codeload.github.com/sergij14/real-time-editor-app/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergij14%2Freal-time-editor-app/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32720247,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","reactjs","socket-io"],"created_at":"2025-06-26T06:01:57.909Z","updated_at":"2026-05-07T02:34:07.295Z","avatar_url":"https://github.com/sergij14.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Case Study: Real-time Editor App - A collaborative text editor\n\n### The Problem\n\nBuilding a collaborative editor is straightforward until multiple users type simultaneously. The naive approach — every client broadcasts its delta and every other client applies it directly — breaks down under real-world latency. Two users editing the same region at the same time produce deltas that are each valid against their local state but conflict when applied out of order on a peer. The result is silent document corruption.\n\nA second problem emerges at scale: if every connected user independently saves the document on a fixed interval, the Redis write rate grows linearly with the number of users. Ten users editing simultaneously means ten redundant full-document writes every two seconds — all writing the same content.\n\n### Key Technical Decisions\n\n**Server-side delta composition**\n\nRather than treating the server as a dumb relay, it maintains an authoritative in-memory `Delta` per document using Quill's operational transform model. Every incoming `text-change` is composed onto this canonical state before being rebroadcast. This means the server always holds the ground-truth document regardless of client timing, and saves are always derived from that authoritative state rather than trusting any individual client's payload.\n\n```\nClient A types → emit delta A → server composes onto authoritative state → broadcast to peers\nClient B types → emit delta B → server composes onto authoritative state → broadcast to peers\n                                ↓\n                         Redis save = server's composed state (not A or B's version)\n```\n\n**Debounced server-initiated save**\n\nThe save responsibility was moved entirely server-side. On each `text-change`, the server resets a per-document 2-second debounce timer. When the doc goes quiet, the server emits a `request-save` event to one client — the one whose change triggered the quiet period — and that client responds with the current contents. This collapses N concurrent saves into one regardless of how many users are active.\n\n**Redis key namespacing and TTL**\n\nDocument content keys are stored as `doc:{id}` and user lists as `users:{id}`. Without this separation, a document with ID `users:abc` would silently overwrite the user list for document `abc`. Every write also refreshes a 24-hour TTL, so inactive documents are automatically evicted without manual cleanup.\n\n**Socket-boundary input validation**\n\nAll payloads entering the server — `docId`, `username`, `delta`, and cursor `range` — are validated at the socket event boundary before any Redis or broadcast operation. `docId` is constrained to `[a-zA-Z0-9_-]{1,64}`, deltas must carry a valid `ops` array, and usernames are trimmed and capped at 50 characters. This prevents malformed data from propagating into storage or peer clients.\n\n**Reconnection resilience**\n\nThe client `get-doc` emit is attached to the socket's `connect` event rather than being fired once on mount. If the socket drops and reconnects, the editor automatically rejoins the document room and reloads the current state — users see a seamless resume rather than a broken editor.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergij14%2Freal-time-editor-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergij14%2Freal-time-editor-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergij14%2Freal-time-editor-app/lists"}