Distributed Transaction Patterns from an MSA Perspective, as Explained by a Kakao Interviewer
Learn the SAGA transaction management technique for maintaining data consistency in distributed environments through a hands-on approach. You will configure three microservices using Spring Boot and Docker, and implement both Orchestration and Choreography patterns using Kafka and MySQL. Through this course, you will master core concepts applicable to real-world scenarios, including the operational principles of distributed transactions, designing compensating transactions, and handling fault recovery.
It was a great opportunity to study distributed transactions!
5.0
keny
92% enrolled
I personally think this might be one of the most beneficial lectures on Inflearn. The content was so substantial that I was able to learn a lot from it. Thank you.
5.0
개발에 미친자
92% enrolled
I really enjoyed the course.
I especially loved how you showed numerous diagrams at the beginning while explaining the overall architecture and its details. Any knowledge gaps or concepts that needed organizing could be checked through the separate course summary files. The Inflearn scripts were also helpful when needed.
Also, the review process where you explained everything step by step again, along with the realistic stories and practical workplace perspectives, was extremely beneficial.
I really enjoyed it. Thank you.
What you will gain after the course
Revealing the Secrets of Designing Fault-Tolerant Distributed Transactions
Orchestration vs. Choreography Patterns: When and how to use them in practice?
Real-time Event-Driven SAGA Transactions Implemented with Kafka
Building a Reliable Compensating Transaction Architecture with Spring Boot
Hands-on Microservices Transaction Practice: Building Directly with Docker
Development · Programming · Backend
The services were divided, but the transactions could not be.
The moment you separate databases for each service, the scope of what can be bound by a single commit ends. When a payment is completed but inventory hasn't decreased, how do you roll it back? This course answers that question with the SAGA pattern.
Difficulty: Beginner
Includes hands-on practice
Spring Boot · Kafka
Section Quizzes
Unlimited access period
From Concept to ImplementationLimitations of Distributed Transactions · SAGA · TCC · 3PC
Electronic Payment ExampleLaunch with Docker Compose and build three applications yourself
Two current developers12-year veteran interviewer at Kakao HQ · Pangyo platform server developer
SAGA is a pattern that breaks down one large transaction into multiple local transactions and reverts them using compensation transactions if a failure occurs.
Where this lecture begins
There is no longer anyone to perform the rollback.
When it was a single unit
Finished with a single commit
If it fails, the database handles the rollback automatically. There is no need for the developer to intervene.
Database per Service
After dividing the services
There is no entity to handle the rollback
Even if the third service fails, the first two have already been committed individually.
In a distributed environment, rollbacks do not happen automatically. we must implement the rollback process through code, and that method is the compensation transaction.
Where this lecture began
This is an actual conversation that took place.
A Kakao developer serving as an interviewer brought up this topic first.
The Kakao interviewer brought up the topic first.
KKakao Interviewer (Developer)It's good to study distributed transactions. Are you familiar with them?
HHongYou're talking about concepts like local transactions or compensating transactions, right?
KKakao Interviewer (Developer)Yes, I'm talking about the SAGA pattern. I always ask about this when I'm interviewing, but since so many people don't know it, I asked because I thought of you.
HHongI've heard of it, but I haven't implemented it down to the core level. I only know the concept because I haven't gone as far as the Database per Service perspective.
KKakao Interviewer (Developer)Then I'll organize the content on this topic and let you know. Let's work on it together while also going through the lectures.
HHongSounds good. Let's go for it.
What SAGA does
It breaks it down, and if it fails, it rolls it back in reverse.
Processing a single order involves multiple services. Each service commits a local transaction to its own database. If a failure occurs in the middle, a series of cancellation tasks are executed in reverse order to undo the previously successful steps.
Create OrderCommit local transaction. If it fails, revert by canceling the order
→
Payment ApprovalIf it fails here, the compensation transactions for the previous steps are executed
→
Inventory DeductionEven if it fails at the last step, payment cancellation and order cancellation will run in reverse
There isn't just one way to undo changes. The Rollback provided by the database and the Compensation we create are different things, and we will start by addressing those differences in Section 4.
What you will learn
In the order of Limitations · Patterns · Comparison · Implementation steps
Why it is a problemStarting from why ACID cannot cross service boundaries from an MSA perspective
Core SAGA ConceptsLocal transactions and compensating transactions. A comparison between modern SAGA and traditional ACID.
ChoreographyA method where services observe events and act independently without a central orchestrator
OrchestrationA method where a central coordinator directs the sequence. A detailed comparison of the pros and cons of both.
Rollback vs CompensationTwo things that the word "reversal" refers to
TCC and 3PCAlternatives to SAGA. For TCC, we will also look at the MySQL design.
Electronic Payment PracticeCreate an environment with Docker Compose and implement three applications yourself
Two types of implementations
Republic or Monarchy
There are two main ways to implement SAGA. This is also the point where opinions differ most frequently in interviews.
CHOREOGRAPHY
There is no central orchestrator. Each service monitors events and performs the next task on its own.
Services are loosely coupled with each other.
It is difficult to understand the whole process because the flow is not located in a single place in the code.
As the number of services increases, events become entangled.
ORCHESTRATION
An orchestrator in the middle directs the sequence.
The flow is gathered in one place, making it easy to read.
The compensation sequence in case of failure is also managed in one place.
Instead, that center can become a single point of failure.
You won't just learn one of the two. In Section 3, we will compare the success and failure flows along with the pros and cons of each, and in the final section, we will build the same example using both methods.
Practice Environment
What will it be built with?
We will create the electronic payment example by dividing it into three applications. The environment will be launched all at once using Docker Compose.
Spring Boot 3.2
Java 17
Docker Compose
Kafka
MySQL
IntelliJ IDEA
Both skeleton code and the completed version are included in the materials. If you find it burdensome to type everything from scratch, you can start with the skeleton code.
It doesn't end with just theory.
In the final section, we will personally build three applications and run them in two different ways.
In the first half, we identify why it becomes a problem and establish the patterns; in the second half, we set up the environment and implement it ourselves.
01
Course Introduction
Course Introduction
Skeleton practice code
Practice code for the final version
Lecture Summary File
Recommended materials to view together
02
Problems and limitations of distributed transactions & Limitations of ACID from an MSA perspective, and the resulting distributed transaction patterns
What problems can the SAGA pattern solve?
Why on earth are distributed transactions problematic?
Key concepts to know when implementing SAGA in modern distributed transactions
Modern SAGA Pattern vs. Traditional ACID
Pros and cons of the SAGA pattern and suitable scenario situations
Section 2 Quiz
03
Representative Implementations of SAGA (Choreography vs Orchestration)
The first independent Choreography of the SAGA pattern: success, failure, and considerations.
Pros and Cons of the SAGA Pattern: Republican Independent Choreography
SAGA Pattern Monarchy Centralized Orchestration
Pros and Cons of SAGA Pattern Monarchical Centralized Orchestration
Detailed Comparison of Choreography vs Orchestration Patterns
Section 3 Quiz
04
A distributed transaction technique with different pros and cons compared to SAGA
SAGA's Rollback vs Compensation
TCC (Try-Confirm-Cancel) pattern and its corresponding actual MySQL design and architecture
3PC (Three-Phase Commit) Comparison
Section 4 Quiz
05
Preparing for SAGA Practice and Configuring the Environment
Overall explanation of the architecture and implementation to be practiced through an electronic payment example
Building a lightweight environment and architecture using docker-compose
The necessity and purpose of Common modules from an MSA perspective
Section 5 Quiz
06
Proceeding with SAGA practice (Choreography vs Orchestration)
The first application that serves as the entrance and exit for all requests
The second application that performs intermediate processing
The final application where data loss is permissible, and testing
Section 6 Quiz
For people like this
Who is this course for?
Non-major developers who want to take on the challenge of designing for high-volume traffic
Those who have heard of MSA and SAGA but did not know the specific design methods
Backend developers who are concerned about traffic scalability and fault tolerance
Developers who want to design complex distributed transactions beyond simple microservices
The current market
Stories about AI replacing developers
New hiring is decreasing, and companies are trying to hire only those who are proven. These are articles that have come out in the past few months.
Krafton, which achieved record-breaking performance, has begun downsizing its workforce. The reason given was its transition into an 'AI-first' company.
Software specialized companies are halting the recruitment of new developers. There are also projections that the hiring of entry-level developers will plummet by 77%.
53% of game designers answered, "AI will replace my job." Cases of layoffs have also been reported.
As companies become more anxious, those being hired must demonstrate a clearer distinction. Ultimately, studying is something you do on your own, but depending on what you look at and from which perspective, the depth of what you can explain changes even when spending the same amount of time. I created this lecture to pass on that very perspective.
Course Reviews
Stories from those who listened first
I copied this directly from the Inflearn course reviews.
"I really enjoyed the lecture. I loved the overall architecture and the accompanying explanations shown through numerous diagrams at the beginning, and I could also check the lecture summary file for any knowledge I might have lacked or concepts that needed organizing. Furthermore, the process of reviewing was explained step-by-step, and I found the realistic stories and practical perspectives to be very beneficial."
Crazy about development · Written after 92% completion
"Personally, I think this might be one of the most informative courses on Inflearn. The content was very substantial and helpful for my learning. Thank you."
keny · Written after 92% completion
"It was a great time to study distributed transactions!"
Pairi2 · Written after 100% completion
Instructor
Created together by two current developers
It was co-created by Choi, a 12-year developer who develops servers at Kakao headquarters and also serves as an interviewer, and Hong, a platform server developer in Pangyo.
KAKAO · BACKEND ENGINEER · 12 years of experience · Interviewer
Choi
I am a 12-year backend developer building servers at Kakao headquarters, and I also serve as an interviewer. In interviews, I focus more on whether a candidate can design systems rather than their knowledge of programming syntax. I have incorporated that exact perspective into this lecture.
"I rarely ask about programming syntax in interviews. I look for whether you can design."
Current Kakao HQ Server Developer · Interviewer · Computer Science Major
High TrafficDistributed ArchitectureInterviewerBackend
Knowledge Sharer · Pangyo Platform Server Development
Hong
I am in charge of platform server development in Pangyo. I continue my activities as a knowledge sharer to share the methods I studied myself and the problems and solutions encountered in practice. The lectures are not created alone, but together with several developers currently working in the field.
"Dividing services is easy, but handling failures after they are divided is difficult."
Platform Server DevelopmentDistributed SystemsMultiple Backend Courses
Q.Can I take this course even if I have no experience with MSA?
⌄
The difficulty level is set to introductory. We start from Section 2 with "Why distributed transactions are a problem." Since we first demonstrate what breaks when each service has its own database, you can follow along even if you have no actual experience operating microservices.
Q.Which one will I learn, Choreography or Orchestration?
⌄
You will learn both. In Section 3, we cover the success and failure flows, pros and cons, and provide a detailed comparison of each. In the final section, we implement the same electronic payment example using both methods. To answer the interview question, "Why did you choose that method?" you need to see the two side-by-side.
Q.What will we be creating in the practice session?
⌄
It is an electronic payment example. We will build three applications: one that serves as the gateway for all requests, one responsible for intermediate processing, and a final application where data loss is permissible. The environment will be configured using Docker Compose, and we will also cover why common modules are necessary in MSA.
Q.Do you cover other patterns besides SAGA?
⌄
Section 4 is where that is covered. We will look at the TCC (Try-Confirm-Cancel) pattern along with actual MySQL design and compare it with 3PC (Three-Phase Commit). Since SAGA is not always the answer, the goal is to enable you to judge which one is appropriate for a given situation.
Q.Is this helpful for interview preparation?
⌄
This was co-created by a developer who serves as an interviewer at Kakao, and it is structured based on questions actually asked in real interviews. Instead of having you memorize fixed answers, it is designed to help you explain pros, cons, and trade-offs. A lecture summary file is also included as a resource.
Write code to handle the rollback process cho việc hoàn tác
After dividing services, what is needed is not a larger transaction, but a different design.
It takes a long time when you're stuck alone. There is a separate space where you can comfortably share everything from parts you get stuck on while taking lectures, questions that arise while applying them to your own service, to stories about your career and the industry.
OPEN CHAT · Developer Community
What do we share?
We discuss real-world problems encountered in practice, the architectures others have chosen, and stories about developer careers. Questions related to the lectures are also welcome.
"The spots where you get stuck are usually where others get stuck too. Asking someone who has already passed through is the fastest way."
I started studying development after becoming interested in it while idling at home, and I am currently responsible for platform server development in Pangyo. I am continuing my activities as a knowledge sharer because I want to provide you with the methods I used to study, as well as the various problems and solutions you may encounter in practice.
These lectures are not created solely through my own knowledge. There are others who collaborate on every lecture.
I'm helping create this course and work as a server developer at Kakao. Actually, I wanted to hide the fact that I'm an interviewer... 😭😭 But I thought this would be such a great topic to cover, so I decided to join this course.
As I mentioned, when I actually conduct interviews at Kakao, I'm not particularly curious about things from a programming perspective. Most of my questions focus on whether someone can do architectural design, and I consider `what kind of concepts this person can come up with` to be extremely important.
Various problems can arise from this perspective, and one of those factors is distributed transactions. That's why I think this course is all the more beneficial.
If you can answer these kinds of questions after taking this course, I think you'll have learned something truly meaningful.
1. Please tell me about the two patterns of SAGA (Choreography VS Orchestration)
2. Please tell me about the differences and pros/cons of these two patterns. I'm particularly curious about throughput and the problems that come with it.
3. Do you know the concept of local transactions?? (If you don't know, I'll explain it) Then how can distributed transactions be managed in relation to these transactions??
4. Please tell me everything you know about distributed transactions in general. I'm curious.
5. Do you know what the Database per Service perspective is??
These are examples of questions I actually ask when I go into interviews. If you know about these areas and can answer them, it would be a great help.
Please show a lot of interest in the course. Thank you!
It's theory-focused. I'd say it's about 80% theory and 20% practice. It doesn't seem suitable for those who want to learn theory and see real-world source code examples. However, it's suitable for those who know nothing about patterns.
Hello, Sim Gyu-hwan! Thank you for leaving a review. I kept the actual implementation code simple because I thought spending time on basic coding wouldn't be very beneficial for you all, but next time I'll prepare content that's closer to real-world practice.
Thank you for the positive feedback!!
I personally think this might be one of the most beneficial lectures on Inflearn. The content was so substantial that I was able to learn a lot from it. Thank you.