Giter Site home page Giter Site logo

hasura / 3factor Goto Github PK

View Code? Open in Web Editor NEW
179.0 38.0 17.0 208 KB

3factor app is an architecture pattern for modern fullstack apps. 3factor apps are fast to build and are highly scalable.

Home Page: https://3factor.app/

Ruby 0.41% HTML 35.63% SCSS 63.96%
3factor realtime-graphql async-serverless architecture-pattern event-handlers

3factor's Introduction

3factor app

3factor app is an architecture pattern for modern full-stack apps. 3factor enables building apps that are robust and scalable from the get go by using modern API architectures along with the power of Cloud. Jump to reference implementation.

We propose an architecture pattern which is composed of 3 factors:

  1. Realtime GraphQL
  2. Reliable eventing
  3. Async serverless

Consider a food ordering application built in traditional way vs 3factor way:

3 factor architecture

We can see here the essense of the architecture i.e. all business logic is invoked via events. The app manipulates state via a GraphQL API and is also subscribed (realtime) to any new state. We will describe the 3factors in more detail below.

Factor #1: Realtime GraphQL

Apart from providing an amazing frontend developer experience, GraphQL is a crucial component in 3factor architecture as it allows flexible API access and realtime capabilities. The GraphQL API should have the following properties:

  • Low-latency: An end-user should see instant feedback of an action (i.e. state manipulation) and not have to wait long on an API (<100ms ideal, upto 1 second at worst).
  • Support subscriptions: Consume information "realtime" from the backend via GraphQL Subscriptions. Avoid the use of continuous polling (for scalability).

Read more...

Factor #2: Reliable eventing

In 3factor, business logic is initiated via events. This removes complex state management in your API layer and defers it to bespoke business logic functions. Events can also be persisted so that entire history of state is available for observability. Further, the event system must have the following 2 properties:

  • Atomic: Mutations to the application state should atomically create event(s).
  • Reliable: Events should be delivered (to any consumer) with atleast-once guarantee.

Read more...

Factor #3: Async serverless

Write business logic as event handling functions. Each function only cares about one event and is hence small & cohesive. The easiest way to deploy such functions is in serverless compute. Serverless minimizes backend ops and gives "infinite" scalability while being cost-efficient. The serverless functions should follow few best-practices:

  • Idempotent: The code should be prepared for duplicate delivery of events.
  • Out-of-order: Events may not be guaranteed to be received in any realtime order. The code should not depend on any expected sequence of events.

Read more...


In short, a 3factor app requires you to remove state management from your API layer. It encourages fine-grained state changes and event generation (in data store) and corresponding event delivery (via event queues) to invoke business logic. The business logic can further change the state which is then delivered to subscribed clients via realtime GraphQL.

The 3factor app architecture is an implementation of the CQRS pattern in many ways. The frontend gives the "commands" and then "queries" (subscribes) for the new state while events invoke the business logic behind the scenes.

Comparison to 12factor.net

The 3factor name is inspired from 12factor.net. 12factor.net, created 7 years ago by the folks at Heroku, is a guide/best-practices for creating microservices based applications for modern cloud. Although the name is similar, 3factor.app is actually an application design pattern.

Reference implementation

A complete step-by-step reference implementation for a 3factor app is available at: github.com/hasura/3factor-example

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.