Coder Social home page Coder Social logo

arv / replicache-sample-chat-cosmosdb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rocicorp/replicache-sample-chat-cosmosdb

0.0 0.0 0.0 69 KB

A port of the replicache-sample-chat app to cosmosdb

Home Page: replicache-sample-chat-cosmosdb-git-main-rocicorp.vercel.app

JavaScript 100.00%

replicache-sample-chat-cosmosdb's Introduction

Replicache Chat (via Next.js/Cosmos DB)

This is a very simple chat sample built with Next.js and Cosmos DB.

Code Layout

  • index.js - A very simple UI that talks to the Replicache client
  • pages/api/init.js - Initializes the Cosmos DB schema. In a real application you'd want to migrate versions. See notes inline.
  • pages/api/[push, pull].js - Endpoints for Replicache's push and pull operations. These just delegate to stored procedures in Cosmos.
  • cosmos/proc/[push, pull].js - Implement the push and pull operations.
  • cosmos/shared/* - Utilities supporting stored procedures.

Big Picture

Replicache requires multikey read/write transactions for its push handler. Cosmos DB offers this feature via "stored procedures", which are written in JavaScript and uploaded to the DB.

This sample uses Cosmos DB stored procedures to implement both the push and pull handler for consistency. There are also performance benefits to this approach since it makes the communication protocol between app server and db server a lot less chatty.

See the cosmos directory for the JavaScript implementation of these procedures. The pages/api/{push, pull} endpoints become thin wrappers that just delegate to the corresponding procedures in the database.

Considerations

  • Cosmos DB has tunable consistency. For correct operation, Replicache requires the consistency level to be Consistent Prefix or better.
  • Cosmos DB only offers consistency guarantees within partitions. This sample puts all data in a single partition. Shoud you need multiple partitions, all data in a single Replicache instance must come from a single Cosmos DB partition.
  • This sample implements Replicache's cookie feature by using a global counter. This is effectively a global lock that limits write throughput. A better implementation would be to use a finer-grained lock. There are also other options for implementing the cookie that are additional effort. Talk to our team if you'd like help working through this.

replicache-sample-chat-cosmosdb's People

Contributors

aboodman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.