SlideShare a Scribd company logo
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly", Anastasiia Mihal
Agenda 1. Problem space
2. Finite state machines (FSMs)
3. RxJS + Focal
4. Key takeaways
5. Resources
Mastering UI Complexity: State Machines and Reactive Patterns
Improve lives by
improving
communication
Our mission
Grammarly by the numbers
70K+
1000+
employees
work together to
build Grammarly
from our hubs or in
their homes.
50K+
organizations
trust Grammarly as
their AI assistant
for work.
500K+ apps
and sites
integrate seamlessly
with Grammarly, so it
works wherever you
do.
40M+ daily
active users
use Grammarly to
show up as the
best versions of
themselves
What does Grammarly do?
1. SETTING THE CONTEXT
Mastering UI Complexity: State Machines and Reactive Patterns
Problem space
Mastering UI Complexity: State Machines and Reactive Patterns
Feature design (simplified)
Mastering UI Complexity: State Machines and Reactive Patterns
1
2
3
4
1. PROBLEM SPACE
Feature requirements
1 2 3
Flexible architecture Feature steps must
happen in fixed order
Activation at the
right moment
SECTION TITLE HERE
Feature behaviour may
change in the future
No random jumping
between feature states
Respond to relevant text
changes only
Mastering UI Complexity: State Machines and Reactive Patterns
1. SETTING THE CONTEXT
Mastering UI Complexity: State Machines and Reactive Patterns
Finite State Machines (FSMs)
Mastering UI Complexity: State Machines and Reactive Patterns
Real-life example: traffic light
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Key concepts: states, transitions, external input
& output
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Feature state machine diagram
IDLE
LOADING
READY
SUCCESS
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Feature state machine diagram
IDLE
LOADING
READY
SUCCESS
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Feature state machine diagram
IDLE
LOADING
READY
SUCCESS
TextService
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Feature state machine diagram
IDLE
LOADING
READY
SUCCESS
TextService
X ms passed since last change
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Feature state machine diagram
IDLE
LOADING
READY
SUCCESS
TextService
API
Text ready for checking
X ms passed since last change
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Feature state machine diagram
IDLE
LOADING
READY
SUCCESS
TextService
API
Text ready for checking
Suggestions ready
X ms passed since last change
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Feature state machine diagram
IDLE
LOADING
READY
SUCCESS
TextService
API
Text ready for checking
Suggestions ready
User input
Shortcut pressed
X ms passed since last change
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Feature state machine diagram
IDLE
LOADING
READY
SUCCESS
TextService
API
Text ready for checking
Suggestions ready
User input
Shortcut pressed
Text ready for checking
X ms passed since last change
500ms
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Time to code </>
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Time to code </>
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Time to code </>
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Time to code </>
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Benefits
● New states don’t break existing logic
● Requirement changes → state
modifications
● State machine diagram = visual model for
stakeholders
● Valid transitions permitted only
● Centralised transition logic
● Current state known and traceable
Feature steps must happen in
fixed order – ✅
Flexible architecture – ✅
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Benefits
● New states don’t break existing logic
● Requirement changes → state
modifications
● State machine diagram = visual model for
stakeholders
● _getNextState() is a pure function
● Each transition verifiable independently
● Separation of concerns = no dependencies
100% Testability
● Valid transitions permitted only
● Centralised transition logic
● Current state known and traceable
Feature steps must happen in
fixed order – ✅
Flexible architecture – ✅
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
We’ve addressed
2 out of 3
requirements
We’ll address the
3rd one, right?
Right?..
Mastering UI Complexity: State Machines and Reactive Patterns
2. FINITE STATE MACHINES (FSMS)
Text is constantly changing
● Typed by the user
● Corrected by other Grammarly features
Activation at the right moment
Callback hell
● Asynchronous operations prone to race conditions
● No way to cancel pending operations if new occur
Mastering UI Complexity:
State Machines and Reactive Patterns
RxJS 🤝 Focal
Mastering UI Complexity: State Machines and Reactive Patterns
Observables Observers
streams of events that occur over time receive notifications when new values are emitted
3. RXJS & FOCAL
Mastering UI Complexity: State Machines and Reactive Patterns
RxJS: key concepts
RxJS: key concepts
3. RXJS & FOCAL
Mastering UI Complexity: State Machines and Reactive Patterns
How to combine the two?
RxJS React
✨ Focal
✨
3. RXJS & FOCAL
Mastering UI Complexity: State Machines and Reactive Patterns
Focal Atoms
Atom
Rx event stream Subscriber
3. RXJS & FOCAL
Mastering UI Complexity: State Machines and Reactive Patterns
Time to code </>: Focal Atoms
3. RXJS & FOCAL
Mastering UI Complexity: State Machines and Reactive Patterns
Time to code </>: Focal Atoms
3. RXJS & FOCAL
Mastering UI Complexity: State Machines and Reactive Patterns
Time to code </>: feature activation
Mastering UI Complexity: State Machines and Reactive Patterns
3. RXJS & FOCAL
Time to code </>: feature activation
Mastering UI Complexity: State Machines and Reactive Patterns
3. RXJS & FOCAL
Time to code </>: feature activation
Mastering UI Complexity: State Machines and Reactive Patterns
3. RXJS & FOCAL
Key takeaways: to choose or not to choose
Mastering UI Complexity: State Machines and Reactive Patterns
FSMs ✅
● Clearly defined states
● Prevent invalid
transitions
● Thorough testing of all
paths
● Complex event timing
● Multiple async
operations
● Streams of events
needing transformation
RxJS ✅
● Automatic UI-state
synchronization
● Reduced state
management code
● Multiple components
observe the same state
Focal ✅
Key takeaways: to choose or not to choose
Mastering UI Complexity: State Machines and Reactive Patterns
FSMs ❌
● Few states or extremely
simple transitions
● Highly dynamic or
runtime-generated
states
● Continuous behaviour >
discrete behaviour
● Simple one-off async
operations
● Straightforward event
handling
● No benefits from stream
composition
RxJS ❌
● Component-local state
only
● Rare shared state
updates
● No need for reactive UI
updates
Focal ❌
Simplify your code with State Machines
Resources
Building Web Applications with Signals at Grammarly
Understanding State Machines
Understanding RxJS Observables & Observers: A
Comprehensive Guide
Mastering UI Complexity:
State Machines and Reactive Patterns
grammarly/focal: Program user interfaces the FRP way
Join us on
Meetup!
Grammarly Tech
Talks Group
Thank you

More Related Content

More from Fwdays (20)

PPTX
"Human-AI Collaboration Models for Better Decisions, Faster Workflows, and Cr...
Fwdays
 
PDF
"AI is already here. What will happen to your team (and your role) tomorrow?"...
Fwdays
 
PPTX
"Is it worth investing in AI in 2025?", Alexander Sharko
Fwdays
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PDF
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
PDF
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
PDF
"Scaling in space and time with Temporal", Andriy Lupa .pdf
Fwdays
 
PPTX
"Provisioning via DOT-Chain: from catering to drone marketplaces", Volodymyr ...
Fwdays
 
PPTX
" Observability with Elasticsearch: Best Practices for High-Load Platform", A...
Fwdays
 
PPTX
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
PPTX
"Istio Ambient Mesh in production: our way from Sidecar to Sidecar-less",Hlib...
Fwdays
 
PPTX
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
PPTX
"Confidential AI: zero trust concept", Hennadiy Karpov
Fwdays
 
PPTX
"Choosing Tensor Accelerators for Specific Tasks: Compute vs Memory Bound Mod...
Fwdays
 
PPTX
"Custom Voice Assistants: Infrastructure, Integrations, and Uniqueness", Yeho...
Fwdays
 
PPTX
"Different Facets of AI: Computer Vision and Large Language Models. How We De...
Fwdays
 
PPTX
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
Fwdays
 
PPTX
"Using AI to Automate Operational Processes at MK-Consulting", Maxim Korzhene...
Fwdays
 
PPTX
"AI in the browser: predicting user actions in real time with TensorflowJS", ...
Fwdays
 
PDF
"Interactive problems", Yuri Artiukh. JavaScript
Fwdays
 
"Human-AI Collaboration Models for Better Decisions, Faster Workflows, and Cr...
Fwdays
 
"AI is already here. What will happen to your team (and your role) tomorrow?"...
Fwdays
 
"Is it worth investing in AI in 2025?", Alexander Sharko
Fwdays
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
"Scaling in space and time with Temporal", Andriy Lupa .pdf
Fwdays
 
"Provisioning via DOT-Chain: from catering to drone marketplaces", Volodymyr ...
Fwdays
 
" Observability with Elasticsearch: Best Practices for High-Load Platform", A...
Fwdays
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
"Istio Ambient Mesh in production: our way from Sidecar to Sidecar-less",Hlib...
Fwdays
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
"Confidential AI: zero trust concept", Hennadiy Karpov
Fwdays
 
"Choosing Tensor Accelerators for Specific Tasks: Compute vs Memory Bound Mod...
Fwdays
 
"Custom Voice Assistants: Infrastructure, Integrations, and Uniqueness", Yeho...
Fwdays
 
"Different Facets of AI: Computer Vision and Large Language Models. How We De...
Fwdays
 
"Machine Learning in Agriculture: 12 Production-Grade Models", Danil Polyakov
Fwdays
 
"Using AI to Automate Operational Processes at MK-Consulting", Maxim Korzhene...
Fwdays
 
"AI in the browser: predicting user actions in real time with TensorflowJS", ...
Fwdays
 
"Interactive problems", Yuri Artiukh. JavaScript
Fwdays
 

Recently uploaded (20)

PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Ad

"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly", Anastasiia Mihal

  • 2. Agenda 1. Problem space 2. Finite state machines (FSMs) 3. RxJS + Focal 4. Key takeaways 5. Resources Mastering UI Complexity: State Machines and Reactive Patterns
  • 4. Grammarly by the numbers 70K+ 1000+ employees work together to build Grammarly from our hubs or in their homes. 50K+ organizations trust Grammarly as their AI assistant for work. 500K+ apps and sites integrate seamlessly with Grammarly, so it works wherever you do. 40M+ daily active users use Grammarly to show up as the best versions of themselves
  • 5. What does Grammarly do? 1. SETTING THE CONTEXT Mastering UI Complexity: State Machines and Reactive Patterns
  • 6. Problem space Mastering UI Complexity: State Machines and Reactive Patterns
  • 7. Feature design (simplified) Mastering UI Complexity: State Machines and Reactive Patterns 1 2 3 4 1. PROBLEM SPACE
  • 8. Feature requirements 1 2 3 Flexible architecture Feature steps must happen in fixed order Activation at the right moment SECTION TITLE HERE Feature behaviour may change in the future No random jumping between feature states Respond to relevant text changes only Mastering UI Complexity: State Machines and Reactive Patterns
  • 9. 1. SETTING THE CONTEXT Mastering UI Complexity: State Machines and Reactive Patterns
  • 10. Finite State Machines (FSMs) Mastering UI Complexity: State Machines and Reactive Patterns
  • 11. Real-life example: traffic light Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 12. Key concepts: states, transitions, external input & output Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 13. Feature state machine diagram IDLE LOADING READY SUCCESS Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 14. Feature state machine diagram IDLE LOADING READY SUCCESS Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 15. Feature state machine diagram IDLE LOADING READY SUCCESS TextService Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 16. Feature state machine diagram IDLE LOADING READY SUCCESS TextService X ms passed since last change Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 17. Feature state machine diagram IDLE LOADING READY SUCCESS TextService API Text ready for checking X ms passed since last change Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 18. Feature state machine diagram IDLE LOADING READY SUCCESS TextService API Text ready for checking Suggestions ready X ms passed since last change Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 19. Feature state machine diagram IDLE LOADING READY SUCCESS TextService API Text ready for checking Suggestions ready User input Shortcut pressed X ms passed since last change Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 20. Feature state machine diagram IDLE LOADING READY SUCCESS TextService API Text ready for checking Suggestions ready User input Shortcut pressed Text ready for checking X ms passed since last change 500ms Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 21. Time to code </> Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 22. Time to code </> Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 23. Time to code </> Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 24. Time to code </> Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 25. Benefits ● New states don’t break existing logic ● Requirement changes → state modifications ● State machine diagram = visual model for stakeholders ● Valid transitions permitted only ● Centralised transition logic ● Current state known and traceable Feature steps must happen in fixed order – ✅ Flexible architecture – ✅ Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 26. Benefits ● New states don’t break existing logic ● Requirement changes → state modifications ● State machine diagram = visual model for stakeholders ● _getNextState() is a pure function ● Each transition verifiable independently ● Separation of concerns = no dependencies 100% Testability ● Valid transitions permitted only ● Centralised transition logic ● Current state known and traceable Feature steps must happen in fixed order – ✅ Flexible architecture – ✅ Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 27. We’ve addressed 2 out of 3 requirements We’ll address the 3rd one, right? Right?.. Mastering UI Complexity: State Machines and Reactive Patterns 2. FINITE STATE MACHINES (FSMS)
  • 28. Text is constantly changing ● Typed by the user ● Corrected by other Grammarly features Activation at the right moment Callback hell ● Asynchronous operations prone to race conditions ● No way to cancel pending operations if new occur Mastering UI Complexity: State Machines and Reactive Patterns
  • 29. RxJS 🤝 Focal Mastering UI Complexity: State Machines and Reactive Patterns
  • 30. Observables Observers streams of events that occur over time receive notifications when new values are emitted 3. RXJS & FOCAL Mastering UI Complexity: State Machines and Reactive Patterns RxJS: key concepts
  • 31. RxJS: key concepts 3. RXJS & FOCAL Mastering UI Complexity: State Machines and Reactive Patterns
  • 32. How to combine the two? RxJS React ✨ Focal ✨ 3. RXJS & FOCAL Mastering UI Complexity: State Machines and Reactive Patterns
  • 33. Focal Atoms Atom Rx event stream Subscriber 3. RXJS & FOCAL Mastering UI Complexity: State Machines and Reactive Patterns
  • 34. Time to code </>: Focal Atoms 3. RXJS & FOCAL Mastering UI Complexity: State Machines and Reactive Patterns
  • 35. Time to code </>: Focal Atoms 3. RXJS & FOCAL Mastering UI Complexity: State Machines and Reactive Patterns
  • 36. Time to code </>: feature activation Mastering UI Complexity: State Machines and Reactive Patterns 3. RXJS & FOCAL
  • 37. Time to code </>: feature activation Mastering UI Complexity: State Machines and Reactive Patterns 3. RXJS & FOCAL
  • 38. Time to code </>: feature activation Mastering UI Complexity: State Machines and Reactive Patterns 3. RXJS & FOCAL
  • 39. Key takeaways: to choose or not to choose Mastering UI Complexity: State Machines and Reactive Patterns FSMs ✅ ● Clearly defined states ● Prevent invalid transitions ● Thorough testing of all paths ● Complex event timing ● Multiple async operations ● Streams of events needing transformation RxJS ✅ ● Automatic UI-state synchronization ● Reduced state management code ● Multiple components observe the same state Focal ✅
  • 40. Key takeaways: to choose or not to choose Mastering UI Complexity: State Machines and Reactive Patterns FSMs ❌ ● Few states or extremely simple transitions ● Highly dynamic or runtime-generated states ● Continuous behaviour > discrete behaviour ● Simple one-off async operations ● Straightforward event handling ● No benefits from stream composition RxJS ❌ ● Component-local state only ● Rare shared state updates ● No need for reactive UI updates Focal ❌
  • 41. Simplify your code with State Machines Resources Building Web Applications with Signals at Grammarly Understanding State Machines Understanding RxJS Observables & Observers: A Comprehensive Guide Mastering UI Complexity: State Machines and Reactive Patterns grammarly/focal: Program user interfaces the FRP way
  • 42. Join us on Meetup! Grammarly Tech Talks Group