Giter VIP home page Giter VIP logo

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

3factor's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

3factor's Issues

network error

Error!: Error: Network error: Failed to fetch

trying to run your demo app but it's failing

image

GraphQL Subscriptions in "serverless"

The documentation notes many times that this is a server-less architecture, but I'm having trouble understanding how you would achieve this without a running graphql server to handle the publisher-subscriber websocket notifications.

It also mentions numerous times that the microservices write to the state, and that the graphql API subscribe to the state changes, but this does not really fit into the graphql pub sub format either.

From all documents I've seen, the subscription logic, and subscription events are handled inside the graphql mutation functions:

Mutation: {
   addEvent() {
      do crud on db
      send websocket notification to subscribers with crud data
   }
}

The diagrams seem to point that graphql is somehow listening on the database for changes which is not the case.

Can you clarify how a graphql subscribes to state changes without actually adding the pub sub logic in the graphql layer?

how to handle errors

The backend may be down. Although 3factor ensures that we receive a success when it comes back up but what about the duration till the backend is down?

Canonical 3F app

Hey there, interesting ideas. They seem well-aligned with the current zeitgeist in various fronts (backend, devops, frontend).

However these ideas are presented without context/references, specific technologies, and detailed-enough examples.

While there are obviously multiple ways of addressing those concerns, I would propose that you create a sample app that one can actually deploy and evaluate. One could review personally that the claims about reliability, latency, etc have an actual basis.

Hope it doesn't sound too fanciful!

Victor

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.