梦见小鬼是什么预兆| 什么牌子的益生菌调理肠胃比较好| 口坐读什么| 耐受性是什么意思| 怀孕后的分泌物是什么样的| 尿素氮偏低是什么原因| 什么症状吃肝胃气痛片| 大便暗红色是什么原因| 复试是什么意思| 胃有灼热感是什么原因| 高锰酸钾有什么作用| 米非司酮片是什么药| 为什么空腹血糖比餐后血糖高| 痛经喝什么药| 英姿飒爽是什么意思| 压车是什么意思| 德国是什么民族| hpv58阳性是什么意思| 菜板什么材质的好| 闺六月是什么意思| 英氏属于什么档次的| 肠梗阻是什么原因引起的| 什么是避孕套| 金牛女跟什么星座最配| 耿直什么意思| mirage轮胎什么牌子| 丑土代表什么| 幽门杆菌的症状是什么| 七宗罪分别是什么| 高级护理是干什么的| 五体投地是什么意思| 梦见鞋子是什么意思| 肛门里面痒是什么情况| 儿童看小鸡挂什么科| eland是什么牌子| 戒掉手淫有什么好处| g1p1是什么意思| 什么泡水喝能降血压| Rm是什么| 女生大姨妈推迟是什么原因| 中管干部是什么级别| 养生吃什么最好| 瘙痒是什么意思| 障碍是什么意思| 豆腐吃多了有什么坏处| 为什么总是打嗝| 香兰素是什么东西| 插科打诨是什么意思| hpv感染吃什么药| 意念是什么| 10度左右穿什么衣服合适| 什么颜色加什么颜色等于黑色| 合作医疗是什么| 抽血后头晕是什么原因| 尿液突然变深褐色是什么原因| 84消毒液不能和什么一起用| 自己开店做什么赚钱| 扁平疣是什么样子图片| 女性阴部潮湿是什么原因| 什么是比| 潜规则是什么意思| 什么是生物制剂药| 病毒性疣是什么病| 血虚吃什么食物可以补| 乙型肝炎e抗体阳性是什么意思| 什么东西可以解酒| 什么是官方旗舰店| 七情六欲什么意思| 张姓为什么出不了皇帝| 桑螵蛸是什么| 年轻人白头发是什么原因引起的| 八月有什么节日| 水鱼煲鸡汤放什么药材| 高烧不退是什么病毒| 丛林法则是什么意思| 18号来月经什么时候是排卵期| 半边脸发麻是什么原因| 90年属什么| 虚岁是什么意思| 大便次数增多是什么原因| 胎监什么时候开始做| 71年出生属什么生肖| 胸部ct挂什么科| 糜烂性胃炎有什么症状| 盆腔检查做什么检查| 疱疹吃什么药| 腰椎间盘突出不能吃什么食物| 容易长痣是什么原因| 吃丝瓜有什么功效和作用| 榴莲什么人不能吃| 9月16号是什么星座| 什么安神助睡眠| 麟字五行属什么| 深圳车牌摇号需要什么条件| 塔姆是什么动物| 子宫肌瘤吃什么药好| 阴虚吃什么食补最快| 献血浆有什么好处| 道什么意思| 淋巴发炎吃什么药好| 北京古代叫什么| 猫吃什么会死| anti是什么意思| 后脑勺痛什么原因引起的| 前列腺肥大是什么意思| 枕头太低了有什么危害| 梦见蚂蚁是什么预兆| 转机是什么意思| 朱元璋为什么不传位给朱棣| 世态炎凉是什么意思| 孕晚期头晕是什么原因| 肋骨下面疼是什么原因| 吃什么降血压的食物| 什么好| 老人爱睡觉什么征兆| 什么叫造影| 梦到和死人说话是什么意思| 糜烂性胃炎吃什么药效果好| swi是什么检查| 身上经常痒是什么原因| 今年是什么生肖年| 爱母环是什么形状图片| o型b型生的孩子是什么血型| 马卡龙为什么这么贵| 四叶草代表什么| 双侧骶髂关节致密性骨炎是什么病| 小孩体检挂什么科| 肺炎吃什么药最有效| gag是什么意思| 屠苏指的是什么| 肾不纳气用什么中成药| 乙肝有什么明显的症状| 黄山四绝指的是什么| 月经前一周是什么期| 炝锅是什么意思| 喝酒脸红是什么原因| 跛行是什么意思| 三奇贵人是什么意思| 代血浆又叫什么| 夜不能寐是什么意思| 什么时候量血压最准确| 湿气重不能吃什么| 雷蒙欣氨麻美敏片是什么药| 九月3日是什么日子| 什么深似海| 海参多少头是什么意思| 骨折吃什么补品| 打桩是什么意思| 脱敏处理是什么意思| 骰子是什么意思| 洗礼是什么意思| 徒手是什么意思| 抱持是什么意思| 肠胃湿热吃什么药| crt是什么意思| 孕妇喝椰子水有什么好处| 高贵的什么| 老板喜欢什么样的员工| 脸黄是什么原因造成的| 美眉是什么意思| 淋巴结发炎挂什么科| rm是什么位置| 嘴唇发黑什么原因| 水肿吃什么药消肿最快最有效| 女人右下巴有痣代表什么| 吃什么有饱腹感还减肥| 喝啤酒不能吃什么| 撕票是什么意思| 黑马什么意思| 血小板低吃什么水果好| 黄水晶五行属什么| 沙中土是什么生肖| d二聚体是什么| 梦见狗咬别人是什么意思| 知恩图报是什么意思| 俄罗斯和白俄罗斯有什么区别| 纳甲是什么意思| 松鼠咬人后为什么会死| 家里为什么会有蟑螂| ufc什么意思| 电镀是做什么的| 什么牌子的燃气灶质量好| 8月份是什么星座| 甲状腺囊实性结节是什么意思| 消字号是什么意思| 婴儿吃不饱有什么危害| 无偿是什么意思| 千里马比喻什么人| 感冒挂什么科室| 属鸡的跟什么属相最配| 沙僧头上戴的是什么| 吃山药有什么好处| 痛心疾首的疾什么意思| 工厂体检一般检查什么| 1990属什么生肖| 盆底肌高张是什么意思| 白细胞减少吃什么药| 种小麦用什么肥料好| kid是什么意思| ct和b超有什么区别| 植物有什么| 北极熊是什么颜色的| 甘蔗男是什么意思| 18kgp是什么金| 拉屎为什么是绿色的| 什么什么的眼睛| 什么是虚岁| marni是什么牌子| 梳头有什么好处| 饿了手抖是什么原因| 出什么什么什么| 2004属什么生肖| 大学体检都检查什么| 霉菌性炎症用什么药效果最好| 女人山根低代表什么| 温碧泉适合什么年龄| 盐酸哌替啶是什么药| 为什么会闰月| 经常头昏是什么原因| 亢奋是什么意思| 10.22是什么星座| 私联是什么意思| 养老院护工都做些什么| 看牙挂什么科| 雌激素是什么意思| hippo什么意思| 几成是什么意思| 第一次坐飞机需要注意什么| 1963属什么生肖| 发烧拉肚子吃什么药| 雫是什么意思| 肌酐高是什么引起的| 什么时候同房容易怀孕| 城隍庙求什么最灵| 眼睛痛是什么病| 脸颊两边长痘痘是什么原因引起的| 风指什么生肖| 马克笔是什么笔| 什么的柳枝| 六是什么意思| 吸渣体质是什么意思| 什么是辐射| 吃南瓜有什么好处| 早期流产是什么症状| 41是什么意思| 亲嘴什么感觉| 拉稀是什么原因| 黑枸杞和什么一起泡水喝比较好| 为什么经常拉肚子| 招字五行属什么| 中华田园犬为什么禁养| 黑茶色是什么颜色| 三叶香是什么菜| 蝉蛹是什么| 什么欲滴| 2月14日什么星座| 东北有什么好玩的景点| 南浦大桥什么时候建成| 梦见浇花是什么意思| 尿酸高吃什么能降| 中国古代四大发明是什么| rpr阴性是什么意思| 凝血五项是检查什么的| 药店最怕什么样的举报| 百度
DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Attention Kubernetes users! DZone is researching how K8s usage is evolving in 2025 — tell us the good, the bad, + the frustrating.

Getting Started With DevSecOps: This Refcard provides actionable insights for embedding security into your DevOps culture and workflows.

Data Engineering: Not your average "AI is changing everything" report. Dive into tooling, strategy, + systems in scalable data ecosystems.

Java Caching: This Refcard explores core caching concepts and demonstrates how to implement them using Java’s JCache API.

Related

  • Modeling Saga as a State Machine
  • Guide to LangChain Runnable Architecture
  • Architecting for Resilience: Strategies for Fault-Tolerant Systems
  • 2-Tier Architecture vs 3-Tier Architecture in DBMS

Trending

  • Debugging Bias: How to Audit Machine Learning Models for Fairness at Scale
  • An Introduction to Agile Architecture
  • Building Generative AI Services: An Introductory and Practical Guide
  • Building a Multi Tenancy Platform Using Camunda
  1. DZone
  2. Software Design and Architecture
  3. Microservices
  4. Designing Fault-Tolerant Messaging Workflows Using State Machine Architecture

车讯:探界者将使用 雪佛兰公布全新9AT变速箱

State machine patterns, such as Stateful Workflows, Sagas, and Replicated State Machines, improve message reliability, sync consistency, and recovery.

By 
Pankaj Taneja user avatar
Pankaj Taneja
·
May. 30, 25 · Analysis
Likes (2)
Comment
Save
Tweet
Share
3.2K Views
百度 在北京农林科学院、科学技术研究院等市属科研院所、生命科学研究所等新型研发机构下放职称评审权,由创新主体自主评价使用人才。

Join the DZone community and get the full member experience.

Join For Free

Abstract 

As a leader of projects for the backend of a global messaging platform that maintains millions of users daily, I was also responsible for a couple of efforts intended to enhance the stability and failure tolerance of our backend services. We replaced essential sections of our system with the help of the state machine patterns, notably Stateful Workflows. The usage of this model led to the elimination of problems in the field of message delivery, visibility of the read receipt, and device sync, such as a mismatch of phone directories. 

The intention of this article is to let the reader know how to keep a messaging infrastructure highly available and adaptable by sharing the practicalities and trials one faces when bringing the said architectures into production.

Introduction 

When dealing with distributed systems, you should always assume that failure will happen. In our messaging platform, it became very clear to us very quickly that unpredictable behavior was not something we should look at as a once-in-a-blue-moon occurrence, as it was in fact the standard state of affairs. Our infrastructure had to deal not only with network partitions and push notification delays but also with user device crashes, and our engineers did a great job in coping with such problems.

Up to that time, instead of having service-level retry logic scattered all over, we selected a more systematic way of achieving the task, which involved the use of state machines. In the end, when we reimagined our business-critical workflows as entities with state, we realized that we had really found the way not only to automate a proper failure recovery process but also to do it in a predictable, observable, and consistent manner. 

This piece will focus on three main designs that we made use of — Stateful Workflows, Sagas, and Replicated State Machines — and how, through them, we not only built an impervious system but also let it respond to any failure scenario gracefully.

Using Stateful Workflows for Message Delivery 

Message delivery is, without a doubt, the most crucial aspect of our system. In the beginning, we used a queue-based system without statefulness to send messages to devices. Unfortunately, we constantly faced unforeseen cases of the process stopping in the middle, which led to a situation where the user did not receive the message at all or received it with a significant delay.

We tackled this problem by introducing the Stateful Workflow Pattern with the help of Temporal:

Message Workflow States

  1. Send Message Initiated
  2. Message Stored
  3. Push Notification Dispatched
  4. Delivery Confirmed
  5. Read Acknowledged

Every transition from one state to another was done by events to which timers and retries were added. When a notification was not delivered (probably due to APNs/FCM complications), the system used an exponential backoff method to retry the request. In case the delivery confirmation failed to arrive in a timely manner, we made a note of the event, and if the customer wished, we might also trigger resolution mechanisms such as sending notifications by email.

Each step was stored in the database's memory, which later enabled workflows to restart from the place where they stopped most recently, even after the system crashed or the node restarted. As a result, the number of messages lost was significantly decreased and the error states were visual in our monitoring applications.

Implementing the Saga Pattern for Multi-Device Sync 

Another vital point is the importance of staying identical in the status of read messages on all the user devices. It means that if the user reads the message on one gadget, the change should be instant on all other gadgets.

The above was implemented in a simple way, it was a Saga:

  • Step 1: Mark the message as read on Device A.
  • Step 2: Sync to cloud state.
  • Step 3: Push read receipt to Devices B and C.

Each of the steps was a local transaction. We would just component the corresponding reactions if one of them fails, thus no consistency would be lost. For example, if the failure is a sync to the cloud, then we would change the state backward and inform A of the problem, so that the result is no partial changes made.

This very method lets us reach even consistency without the need for global locks or distributed transactions, which are both intricate and accident-prone.

Using Replicated State Machines for Metadata Storage 

In order to keep the data, like the conversation state and preferences, in a consistent state, we have employed Replicated State Machines based on the Raft agreement protocol. It is this design that enabled us to:

  • Appoint a leader to manage writes
  • Copy the changes to all followers
  • Bring the state back by getting logs, if there is a crash

This method was specifically beneficial for ensuring that we have a persistent chat indexing service and group membership management, where the state view was always correct.

Comparative Analysis of Patterns

I compared the most common state machine-based fault tolerance patterns to arrive at a solution that worked well for us.

Aspect

Replicated State Machine

Stateful Workflow

Saga Pattern

Primary Goal

Strong consistency & availability

Long-running orchestration

Distributed transaction coordination

Consistency Model

Strong (linearizable)

Eventually consistent (recoverable)

Eventually consistent

Failure Recovery

Re-execution from logs

Resume from persisted state

Trigger compensations

Tooling Examples

Raft (etcd, Consul), Paxos

Temporal, AWS Step Functions

Temporal, Camunda, Netflix Conductor

Ideal For

Consensus, leader election, config stores

Multi-step business workflows

Business processes with rollback needs

Complexity

High (due to consensus)

Moderate

High (compensating logic needed)

Execution Style

Synchronous (log replication)

Asynchronous, event-driven

Asynchronous, loosely coupled


Results and Benefits

Implementing state machine patterns brought the following improvements that could be measured:

  • Message delivery retries fell by 60%.
  • Read receipt sync issues were cut down by 45%.
  • Service crashes recovery time reached under 200ms.
  • Incident resolution time thus got decreased by observability.

Furthermore, we managed to come up with internal tools such as dashboards obtained through the visualization workflow state per message during on-call incidents.

Conclusion

In a messaging system, reliability is not an add-on — it's a must. The users assume that their messages are delivered, read, and synchronized at the same moment. Therefore, using state machines to model essential workflows, we developed a fault-tolerant system that could gracefully recover from dangers. The decomposition of Stateful Workflows, Sagas, and Replicated State Machines gave us the means to regard faults as equal entities in our architecture.

Although the implementation was a bit of a hassle, the benefits of robustness, clarity, and operational efficiency were significant. These patterns are now the foundation of how we are thinking of building our services throughout the organization in a strong manner.

Architecture Machine Fault (technology) workflow

Opinions expressed by DZone contributors are their own.

Related

  • Modeling Saga as a State Machine
  • Guide to LangChain Runnable Architecture
  • Architecting for Resilience: Strategies for Fault-Tolerant Systems
  • 2-Tier Architecture vs 3-Tier Architecture in DBMS

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

在减肥期间吃什么最好 eb病毒是什么意思 生理期可以吃什么水果 阉割是什么意思 阴道壁是什么样的
吃什么奶水多 萎缩性胃炎吃什么药好 女的什么时候退休 五月17号是什么星座 小儿麻痹什么症状
slogan是什么意思啊 呻吟是什么意思 银耳是什么 pussy 什么意思 夏天有什么动物
六月是什么夏 小孩爱吃手指头是什么原因 一什么波纹 乌豆是什么 胰腺有什么作用
月经为什么是黑色的hcv9jop3ns9r.cn 彩超低回声是什么意思hcv9jop3ns0r.cn 拿的起放的下是什么意思hcv9jop0ns9r.cn vans什么意思hcv9jop6ns2r.cn 海洋中最大的动物是什么hcv8jop0ns1r.cn
癫痫不能吃什么hcv8jop5ns9r.cn 尘肺病吃什么能排出尘hcv9jop1ns2r.cn 左腹部是什么器官hcv9jop6ns4r.cn 红对什么hcv9jop3ns9r.cn 为什么蚊子咬了会起包hcv7jop7ns4r.cn
睡觉时身体抽搐是什么原因hcv9jop5ns4r.cn 强肉弱食是什么意思hcv9jop0ns3r.cn 大便什么颜色是正常的hcv8jop2ns7r.cn 核磁共振检查什么hcv7jop9ns8r.cn 三七粉吃了有什么好处hcv8jop4ns6r.cn
睡觉多梦是什么原因hcv8jop2ns1r.cn 吃什么白头发变黑clwhiglsz.com 血清高是什么原因adwl56.com 破气是什么意思hcv9jop3ns9r.cn 浮世是什么意思hcv8jop6ns7r.cn
百度