Redux Remote is a high level networking library for Redux.

Overview

Redux Remote

Redux Remote is a high level networking library for Redux. It runs Redux on both client and server, maintaining the same state. It allows users to use Redux as the only API for state transfer between client and server.

Redux Remote is designed for indie and small multiplayer online games, or more generally apps with requirements:

  • Realtime
  • <100ms latency
  • Atomic state updates.

Why Use It

Redux Remote offers everything Redux offers plus more:

  • Quick Start: You can build working apps without a single line of networking code.
  • Simple Stack: No need to design and implement REST APIs. Redux Remote directly plumbs updates into Redux stores.
  • Realtime: A server pushes updates to clients as the updates happen.
  • Gaming Grade Latency: Updates from a client reach other clients in <100ms round trip time, as they happen in memory.
  • Authority: A server owns the logic to update state, highering the bar for malicious clients to tamper with shared state.
  • Atomicity: Redux updates state synchronously, preventing concurrent updates from corrupting data.
  • Eventual Consistency: A server is the single source of truth, constantly pushing clients to match the same state.
  • Extensibility: Supported by the Redux ecosystem, you can use as few or as many addons as you need. For example, a server can gain storage capabilities with redux-persist without a database.
  • Focus: If you do not need to worry about networking, API, or database, you get to work on all the business logic that matters.

Installation

yarn add @yehzhang/redux-remote

(Unfortunately, redux-remote package is taken by an archived repository. We are working on it!)

Usage

The usage involves adding reconcileReducer and clientMiddleware to your client setup, and startServer to your server setup:

// client.js
import { createStore, applyMiddleware } from 'redux';
import { clientMiddleware, reconcileReducer } from '@yehzhang/redux-remote';
import port from './port';
import rootReducer from './reducers';

const store = createStore(
  reconcileReducer(rootReducer),
  applyMiddleware(
    // Other middlewares go above here...
    clientMiddleware({
      uri: `ws://localhost:${port}`,
    })
  )
);

// server.js
import { createStore } from 'redux';
import { startServer } from '@yehzhang/redux-remote';
import port from './port';
import rootReducer from './reducers';

const store = createStore(rootReducer);
startServer(store, {
  port,
});

If you use other middlewares in addition to clientMiddleware, make sure to put clientMiddleware after them in the composition chain because the middleware delegates actions to server and potentially skips the following middlewares. Alternatively, consider moving client side middlewares to server side.

Why I Built This

I am a fan of serverless. I love how it voids the burden of building a server, which can be half of the work in a client-server architecture. However, there are some blocking issues when I try to build an fast-paced, action-based multiplayer online games with serverless:

  • The latency is unacceptably high. A typical round trip time is user noticable, because database accesses are slow. If a serverless function cold starts, the latency will be even higher. Google search shows me an interesting blog measurnig exact latency numbers, which aligns with my impression.

  • The game can still use a server. Many in game actions require atomic updates to shared state, and multiple clients can request such updates simultaneously (e.g. increments to team scores on a scoreboard). At minimum, the clients need a serverless function to sequentialize simultaneous updates, such that they do not update based on stale state. However, a single database access is already slow, let alone sequentialized ones. One solution is to add an in-memory cache (such as Redis) for shared state and update that instead. However, an in-memory cache is expensive and unnecessarily complex. The lowest tier of ElasticCache on AWS is $10/month. For comparison, the lowest tier of EC2 server is $5/month, which is sufficient for small games like what I am building. Why use an in-memory cache when I can use memory?

Therefore, I come to a conclusion that serverless is just not ready for certain types of games yet. I need a client-server architecture, and a library for the best of both worlds.

How It Works

Redux Remote is a simple library. In essense, it:

  1. Keeps one Redux store in a client and one in a server. Both stores share the same state.
  2. Delegates client dispatched actions to the server.
  3. Sends updated state back to the client using WebSocket.
You might also like...

High-level API for working with binary data.

High-level API for working with binary data.

jBinary ![Gitter](https://badges.gitter.im/Join Chat.svg) Binary data in JavaScript is easy! jBinary makes it easy to create, load, parse, modify and

Dec 29, 2022

A web component that allows you to run high level programming languages on your websites (static websites included!)

Code-Runner-Web-Component A web component that allows you to run high level programming languages on your website via the public Piston API Show your

Dec 16, 2022

Resize image in browser with high quality and high speed

pica - high quality image resize in browser Resize images in browser without pixelation and reasonably fast. Autoselect the best of available technolo

Dec 27, 2022

A Higher Order Component using react-redux to keep form state in a Redux store

A Higher Order Component using react-redux to keep form state in a Redux store

redux-form You build great forms, but do you know HOW users use your forms? Find out with Form Nerd! Professional analytics from the creator of Redux

Jan 3, 2023

Redux-todos - simple react, redux todos

Redux Todos Please star this repo if you like ⭐ It's motivates me a lot! Getting Started This project was bootstrapped with Create React App. Stack Av

Jul 29, 2022

🚀 A well-structured boilerplate and Starter for Next.js 12+, Tailwind CSS 3, Redux, Redux Thunk, and TypeScript

🚀 A well-structured boilerplate and Starter for Next.js 12+, Tailwind CSS 3, Redux, Redux Thunk, and TypeScript ⚡️ Made with developer experience first ESLint + Prettier + Lint-Staged + VSCode setup

Nov 28, 2022

Next js boilerplate with redux toolkit, redux persist and axios

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Apr 25, 2022

Trying 5 Redux Alternatives (Zustand, Recoil, Jotai, Rematch and Redux-Toolkit). Expalined on CoderOne Ytb channel

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Oct 3, 2022

React Hooks library for remote data fetching

React Hooks library for remote data fetching

Introduction swr.vercel.app SWR is a React Hooks library for remote data fetching. The name “SWR” is derived from stale-while-revalidate, a cache inva

Jan 4, 2023

React Hooks library for remote data fetching

React Hooks library for remote data fetching

Introduction swr.vercel.app SWR is a React Hooks library for remote data fetching. The name “SWR” is derived from stale-while-revalidate, a cache inva

Jan 8, 2023

Low-level CSS Toolkit – the original Functional/Utility/Atomic CSS library

Basscss Low-level CSS toolkit – the original Functional CSS library https://basscss.com Lightning-Fast Modular CSS with No Side Effects Basscss is a l

Dec 31, 2022

The smallest, simplest and fastest JavaScript pixel-level image comparison library

The smallest, simplest and fastest JavaScript pixel-level image comparison library

pixelmatch The smallest, simplest and fastest JavaScript pixel-level image comparison library, originally created to compare screenshots in tests. Fea

Jan 8, 2023

Super Low-Level Raster Reprojection and Resampling Library

geowarp Super Low-Level Raster Reprojection and Resampling Library install npm install -S geowarp usage const geowarp = require("geowarp"); const proj

Nov 9, 2022

🛠️construct-js is a library for creating byte level data structures.

🛠️construct-js is a library for creating byte level data structures.

Dec 14, 2022

A fully-typed, low-level, and HyperScript-like Frontend Library 🚀

A fully-typed, low-level, and HyperScript-like Frontend Library 🚀

Apr 4, 2022

Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.

Select2 Select2 is a jQuery-based replacement for select boxes. It supports searching, remote data sets, and pagination of results. To get started, ch

Jan 1, 2023

Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.

Select2 Select2 is a jQuery-based replacement for select boxes. It supports searching, remote data sets, and pagination of results. To get started, ch

Jan 4, 2023

local storage wrapper for both react-native and browser. Support size controlling, auto expiring, remote data auto syncing and getting batch data in one query.

react-native-storage This is a local storage wrapper for both react native apps (using AsyncStorage) and web apps (using localStorage). ES6 syntax, pr

Dec 16, 2022

Dynamically set remote origins at runtime within hosts

external-remotes-plugin Host webpack.config const config = { ...otherConfigs plugins: [ new ModuleFederationPlugin({ name: "app1",

Nov 25, 2022
Releases(0.1.1)
Owner
Simon Zhang
Simon Zhang
Node.js library to receive live stream chat events like comments and gifts in realtime from TikTok LIVE.

TikTok-Live-Connector A Node.js library to receive live stream events such as comments and gifts in realtime from TikTok LIVE by connecting to TikTok'

David 399 Jan 4, 2023
JavaScript library that adds a 'read more' functionality on the text blocks that is applied to.

ReadMore.js JavaScript library that adds a 'Read more/less' functionality on the text blocks that is applied to. API & Usage // Initialise var destroy

George Raptis 29 Oct 14, 2022
This Repository implements an Authenticated Websocket Server built in Node Js along ws library.

websockets-authentication-server This Repository implements an Authenticated Websocket Server built in Node Js along ws library. Features Authenticate

M.Abdullah Ch 7 May 5, 2023
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Node IPC 43 Dec 9, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
🤵 Social networking website mimic of tumblr

CMPLR CMPLR ?? Table of Contents About Get started Technology Screenshots File structure ?? About Responsive Frontend which mocks tumbler ui/ux. ?? Ge

gaser ashraf 14 Feb 11, 2022
An open-source visualization library specialized for authoring charts that facilitate data storytelling with a high-level action-driven grammar.

Narrative Chart Introduction Narrative Chart is an open-source visualization library specialized for authoring charts that facilitate data storytellin

Narrative Chart 45 Nov 2, 2022
:lock: Secure localStorage data with high level of encryption and data compression

secure-ls Secure localStorage data with high level of encryption and data compression. LIVE DEMO Features Secure data with various types of encryption

Varun Malhotra 602 Nov 30, 2022