3factor Apps & Event-driven Programming

·

2 min read

What is event-driven programming?

Event-driven programming is a programming model that's driven by events triggered by the user. The main event-loop initiates the appropriate event-handler deals with the event as and when an event is triggered by the user.

What are 3factor apps?

3factor app, an architecture pattern for building modern full-stack apps, helps build apps that are robust, scalable, and leverage modern API architectures.

3factor app closely follows the event-driven programming paradigm.

The 3 factors in 3factor architecture are:

  1. Real-time GraphQL
  2. Reliable Eventing
  3. Async Serverless

Factor #1: Realtime GraphQL

GraphQL has real-time capabilities and provides flexible API access, and for the 3factor model, should:

  • have low-latency, where an end-user is able to receive instant feedback of any state manipulation,
  • and support subscriptions, by consuming information in a "real-time" fashion from the backend via GraphQL subscription while avoiding continuous polling.

Factor #2: Reliable Eventing

Both the event-driven programming model and the 3factor app architecture pattern delegates complex business logic (and state management) to bespoke functions, leaving the API layer free of such things. Events can be persisted for observability and the event system should:

  • be atomic: mutations to app state should atomically create events,
  • and be reliable: events are delivered with an at-least-once guarantee.

Factor #3: Async Serverless

Write business logic as event handling functions and as such, these functions are small and cohesive because they deal with just one event alone. Now deploy these functions in serverless compute for "infinite" scalability, while being:

  • idempotent: being prepared for duplicate delivery of events,
  • and be prepared for out-of-order events.

UX for GUIs

Event-driven programming and the 3factor app architecture are both super useful for building modern apps, especially those that have a GUI. One advantage of this is that we can utilize the concept of optimistic UI where we update the user of the expected UI state since our process is reliable and atomic.