Prototype of real-time comments and a proposal of how to make it "production-ready".

Overview

Real-time comments prototype

Simple demonstration of real-time commenting.

Installation

After forking it, run npm install, then you need two environment variables in an .env file for it to run during development.

PORT: 3000

CONNECTION_URL: http://localhost:3000

Development

You'll need to run two terminals (or bring in a process manager like concurrently/pm2-dev if you like):

Start the Remix development asset server

npm run dev

In a new tab start your express app:

npm run start:dev

This starts your app in development mode, which will purge the server require cache when Remix rebuilds assets so you don't need a process manager restarting the express server.

How would we scale and make this production-ready?

My initial diagram of how the design may be.

real-time-comments-prototype-scale

  • On the first render of the clients, we need to return the initial data, which the clients would get by making GET requests to API endpoints like: /comments, /reactions/{commentId} etc. The APIs would read from the database using the ORM.

  • After the first render, the clients can listen for updates or write to the sockets (listen to events and emit events when writing).

  • When events have been emitted from a client, the server responds to the sender and all the other related clients with the data, then the write to the database happens. The write to the database sort of happens in the background. This way it isn't blocking the clients from receiving the data.

Data (User, Comment, Reaction)

Since our data is quite relational & structured, and considering today's ways of scaling SQL databases (i.e. Vitess), a SQL database fits our scenario.

Data modelling in an image:

This is surely not complete, please check open questions section below.

reactions-drawing

Tools (ORM and DB)

Prisma as ORM:

  • Amazing DX, type-safety is super awesome, works well with SQL databases.

  • Build fast and make fewer errors.

Planetscale as DB:

  • A SQL database.

  • Based on Vitess. Performant, highly available, can scale horizontally and more.

  • From their website: "...With horizontal sharding and unlimited connections, you can harness the power of Vitess without hiring a team of engineers."

  • Amazing Git-like work flow to be productive.

  • Works great with prisma.

Pagination when tons of comments

Three options come to mind when handling pagination for comments, i.e. in a Slack Thread.

  • Infinite Paging: User scrolls down to the bottom and clicks on a button to load the next 10 comments.

  • Infinite Loading: User scrolls down to the bottom and the next 10 comments gets loaded. We can detect that via intersection oberserver.

  • List virtualization: Only render comments that is within the user's window (what the user sees), and dynamically render them as the user scrolls.

The option with the best UX for i.e. a Slack Thread, to me would be List virtualization. This way we keep it performant and don't load all the comments, but at the same time from the user's perspective, it feels nice, since they don't have to consistently wait for another bunch of comments to be loaded.

Confidence

In order to achieve confidence our app is working as it should, we of course need testing.

It is important that we write the right tests, and really focus on resembling the user, otherwise at least focus on the behavior, and not test implementation details.

For the tests since we will likely need to spin up multiple tabs or browsers, in order to test the real-time behavior and how it works for multiple users, Playwright fits into this.

Cypress is amazing, but for our situation it is limited, and we won't achieve full confidence by testing with a single browser.

Open Questions/Thoughts

  • Reaction Model:

Right now I'm not 100% sure if the data modelling would work as in the diagram.

Where do we get our labels (3rd party API, hard-code, ...)? Do we even need a label? I could imagine if a user searches for an emoji typing "smiley" for example.

The encoding of the emojis, from researching it seems like they are typically encoded as the type utf8mb4?

  • Count of Reactions:

If we switch to NoSQL, we could dynamically add a count column to each comment to keep track of the amount of a specific reaction, by composing it with its label. An example: "smiley" + "Count", would turn into smileyCount property, which would exist as long as it is equal to or greater than one, if less, it gets removed.

Otherwise we may have to add a count column for each type of reaction via its label. Can likely be done by writing a script, but how efficient that is, is a different question.

Demo

demo-prototype.mp4
You might also like...

Perma is a prototype of permanent video storage and viewing using Next.js, Arweave, and Bundlr.

Perma is a prototype of permanent video storage and viewing using Next.js, Arweave, and Bundlr.

PERMA Perma is a prototype of permanent video storage and client-side rendering using Next.js, Arweave, and Bundlr. Technologies used: Arweave - File

Oct 22, 2022

Blog-webapp - A simple webapp prototype that serves tech news, blogs, and anything else a developer might want to learn or get help with

Blog-webapp - A simple webapp prototype that serves tech news, blogs, and anything else a developer might want to learn or get help with

Blog Web app A simple webapp prototype that serves tech news, blogs, and anythin

Nov 3, 2022

Decentralized Twitter prototype built with Polygon, GraphQL, Next.js, Ceramic, Arweave, and Bundlr

Decentralized Twitter prototype built with Polygon, GraphQL, Next.js, Ceramic, Arweave, and Bundlr

Titter - Web3 Social chat beta as fuck đź›  Built with Next.js, Arweave, Bundlr, Ceramic, GraphQL, & Polygon How it works This is a working prototype of

Dec 14, 2022

Fries helps you prototype Android apps using HTML, CSS, and JavaScript.

Fries v2.0.5 Fries is an awesome mobile UI framework for Android apps using just HTML, CSS, and Javascript and is inspired by Ratchet. NOTE: Unfortuna

Dec 29, 2022

A prototype on how web3 technology can enable us to build an open, immutable, reproducible, and permanently accessible scientific record.

A prototype on how web3 technology can enable us to build an open, immutable, reproducible, and permanently accessible scientific record.

Web3 Research A prototype on how web3 technology can enable us to build an open, immutable, reproducible, and permanently accessible scientific record

Nov 27, 2022

Prototype Pollution exploits collection

Prototype Pollution Exploits Intro This repository is a collection of exploits for Prototype Pollution vulnerability. If you're not familiar with the

Dec 10, 2022

Client-Side Prototype Pollution Tools

Client-Side Prototype Pollution Tools

Client-Side Prototype Pollution Tools Match rules for Burp Software Version Reporter extension Match rules that passively detect vulnerable libraries

Oct 4, 2022

client-side prototype pullution vulnerability scanner

client-side prototype pullution vulnerability scanner

JSPanda JSpanda is client-side prototype pollution vulnerability scanner. It has two key features, scanning vulnerability the supplied URLs and analyz

Dec 25, 2022

A prototype snap for injecting gas fee prices into a confirmation window that also serves as the basis for a 5-minute Snaps tutorial

A prototype snap for injecting gas fee prices into a confirmation window that also serves as the basis for a 5-minute Snaps tutorial

@Montoya/gas-fee-snap A simple Snap example based on @MetaMask/template-snap. Read below for a tutorial! Prerequisites Before you begin, make sure you

Dec 8, 2022
Owner
Tiger Abrodi
Software Craftsman.
Tiger Abrodi
MUI Core is a collection of React UI libraries for shipping new features faster. Start with Material UI, our fully-loaded component library, or bring your own design system to our production-ready components.

MUI Core MUI Core contains foundational React UI component libraries for shipping new features faster. Material UI is a comprehensive library of compo

MUI 83.6k Dec 30, 2022
Nouns On-Chain Proposal Simulation and Analysis

Nouns Diligence Nouns On-Chain Proposal Simulation and Analysis For Voters Technical reports for all reviewed proposals can be found in the reports fo

Nouns 23 Dec 26, 2022
Proposal(s) for a stable Deno FFI API

Proposal(s) for a stable API for Deno FFI In this repository I propose a possible stable APIs for Deno FFI. The proposals are split into folders by to

Aapo Alasuutari 6 Dec 5, 2022
The proposal of this repository is having a scaffold with some scenarios where you can challenge your front-end knowledge.

Frontend Kata / Interview ?? Hello developer! The proposal of this repository is having a scaffold with some scenarios where you can challenge your fr

Adrián Ferrera González 2 Nov 11, 2022
Open source project that make it easy to sync your calendars in real time.

Syncit 2.0 - We make it easy to sync your calendars in real time. This is an Open source project! Installation Run yarn in order to install all depend

Tikal Knowledge, Ltd. 6 Dec 15, 2022
Rent-A Movie is a website based on movie renting. The user can leave likes, comments or make reservations for movies they would like to rent. Made using tvMaze API, Involvement API, HTML, SASS and JavaScript

Rent-A Movie "Rent-A Movie" is a website for movie renting where you can make reservations, add comments & likes or just get details about movies that

Zeeshan Haider 19 Aug 23, 2022
A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp.

Basic2Lisp A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp. Syntax Print-Sth Put some-value to standard output. PRI

Hana Yabuki 5 Jul 10, 2022
Compile-time tests for types. Useful to make sure types don't regress into being overly-permissive as changes go in over time.

expect-type Compile-time tests for types. Useful to make sure types don't regress into being overly-permissive as changes go in over time. Similar to

Misha Kaletsky 82 Jan 8, 2023
Simple shopping cart prototype which shows how React components and Redux can be used to build a friendly user experience with instant visual updates and scalable code in e-commerce applications.

This simple shopping cart prototype shows how React components and Redux can be used to build a friendly user experience with instant visual updates a

Ivan Kuznietsov 3 Feb 8, 2022
Been interested, studying, and developing blockchain security with a Zero Knowledge Proof (ZKP) and create a prototype on the current issue with Philippine's upcoming election. đź“Ą

Implementation of Zero Knowledge Proofs in Cryptographic Voting ?? Reference: Cryptographic Voting – A Gentle Introduction Overview ????‍?? The main i

Karl Joseph Saycon 2 Apr 11, 2022