L2 Support Engineer · Fintech · Week 1
Week 1 Day 5
Today's Topic

Transaction Flow

When a customer pays online, what actually happens in the background? Today you learn the full journey of a transaction — from the moment someone taps "Pay" to the moment money moves.

API Message Queue Database Lifecycle Trace a Transaction
01 The Simple Idea First
Real-life Analogy

Think about ordering food at a restaurant.

You tell the waiter what you want → (API) — the waiter takes your order and passes it to the kitchen.

The kitchen has a ticket board with all orders queued up(Message Queue) — orders are handled one by one in order, so nothing gets lost or mixed up.

The chef cooks it and the order is marked as done → (Database) — the final record is written: "Table 4 had a burger, paid, completed."

Every payment transaction works exactly like this. API takes the request. Queue lines it up safely. Database stores the final result.

02 The Three Key Concepts — Explained Simply
🚪
Concept 1 — API
Application Programming Interface
"The front door of your system"

An API is basically a gate or a door that your system opens to the outside world. When a customer clicks "Pay Now", their app sends a message to your company's API. The API receives that message, checks if it looks correct, and then passes it inside the system.

Think of it as a receptionist at a bank. You walk in (you = the customer's request), the receptionist checks your ID and your request, and then sends you to the right department. The receptionist doesn't do the actual work — they just receive and route.

In fintech, the API checks things like: Is this a valid request? Does this account exist? Is the amount correct? If yes — it accepts it and moves it along. If no — it immediately sends back an error.

Common API responses you'll see as L2:
200 = Success  |  400 = Bad request (wrong data sent)  |  401 = Not authorized  |  500 = Server crashed
📬
Concept 2 — Message Queue (MQ)
Message Queue
"The waiting room that keeps everything safe and in order"

After the API accepts the request, it doesn't process the payment directly. It drops the request into a Message Queue — basically a safe waiting line. The queue holds the transaction until the system is ready to process it.

Why does this exist? Imagine 10,000 people paying at the same time. If all 10,000 hit the database directly at once, it would crash. The queue controls the flow — it feeds the database one by one at a manageable speed. Nothing gets lost even if the system is temporarily busy.

Think of it like a post office sorting room. All the letters (transactions) come in at once, get sorted into a line, and are delivered one by one in the correct order.

Common MQ tools you'll hear about: RabbitMQ, Apache Kafka, IBM MQ, ActiveMQ. They all do the same basic job — hold messages in a queue until they're processed.
🗄️
Concept 3 — Database (DB)
Database
"The final record keeper — where everything is written permanently"

The database is where the transaction is finally written and stored forever. Once the message comes out of the queue and gets processed, the result — success or failure — is saved in the database. This becomes the permanent record.

Think of it as the official register at a bank. Every transaction, every balance change, every account update — written in the book permanently. If someone asks "did this payment go through?", you check the database. It's the single source of truth.

As an L2 engineer, you'll often query the database to check if a transaction was recorded, what status it has, and exactly when it happened. This is how you confirm whether a payment truly went through or got stuck somewhere before reaching the DB.

Common DB tools you'll see: MySQL, PostgreSQL, Oracle DB, Microsoft SQL Server. In fintech, Oracle and PostgreSQL are very common for transaction systems.
03 The Full Transaction Flow — Step by Step

🔁 What happens when a customer taps "Pay Now"

👤
Step 1 — Customer
Customer taps "Pay Now"
The customer enters their card details and hits pay. Their app or browser sends this as a request to your company's API.
POST /api/v1/payments → { amount: 500, card: "****1234" }
🚪
Step 2 — API Layer
API receives and validates the request
The API checks: Is the amount valid? Is the account real? Is the token correct? If everything checks out, it accepts the request and sends it forward. If not, it returns an error instantly.
API Response: 200 OK → Request accepted, queuing now...
📬
Step 3 — Message Queue
Transaction goes into the queue
The request is placed into the Message Queue. It waits here safely in line. Even if 10,000 payments come in at once, none get lost — they just wait their turn in the queue.
Queue: [TXN-9821, TXN-9822, TXN-9823 ← your payment]
⚙️
Step 4 — Worker / Processor
Worker picks up the transaction and processes it
A background worker pulls the transaction from the queue, talks to the bank or card network to actually move the money, and checks if the payment was approved or declined.
Worker: Processing TXN-9823 → Bank approved → Status: SUCCESS
🗄️
Step 5 — Database
Result is written to the database
The final result — success or failure — is saved permanently in the database. The customer's account balance is updated. A transaction record is created with timestamp, amount, and status.
DB Record: TXN-9823 | Amount: 500 | Status: SUCCESS | Time: 14:32:05
🔔
Step 6 — Notification
Customer gets confirmation
An SMS or email is sent to the customer: "Payment of PKR 500 successful." The whole process — from tap to notification — typically takes 2 to 5 seconds.
SMS: "Your payment of 500 was successful. Ref: TXN-9823"
04 Trace a Transaction — Hands-on Lab

What does "tracing a transaction" mean?

When a client says "a payment failed" or "I don't know if the money went through" — your job is to trace that transaction. That means following it through each layer: API → Queue → Database, and finding exactly where it got stuck or failed.

You do this by checking logs (records of everything the system did) and querying the database (looking up the transaction by its ID or reference number).

🔍 Transaction Trace — TXN-9823 · Alpha Bank Scenario: Client says "payment didn't go through"
Step Layer What You Check What You Found Status
01 API Did the API receive the request? API log shows request received at 14:32:03. Returned 200 OK. ✓ OK
02 Queue Did it enter the Message Queue? Queue log shows TXN-9823 entered at 14:32:03. Picked up by worker at 14:32:04. ✓ OK
03 Worker Did the worker process it? Worker log shows processing started. Then: ERROR: Bank gateway timeout after 30s ✗ FAILED
04 Database Was anything written to the DB? DB query shows TXN-9823 exists with Status: FAILED. No money was deducted. ✗ FAILED
05 Notification Was customer notified? SMS sent: "Your payment of 500 could not be processed. Please try again." ✓ Sent

What did the trace tell us?

The transaction made it all the way through the API and queue successfully. It failed at the Worker level — specifically when trying to connect to the bank's gateway. The bank's system timed out and didn't respond in time. This is not your system's fault — it's the bank's gateway.

Your next step: raise this with the bank's technical team, share the TXN ID and timestamp, and ask them to check their gateway logs. Update the Jira ticket with your findings.

05 Where to Look When a Transaction Fails
🚪
API Layer

Check API Logs

  • Did request arrive?
  • What HTTP status was returned?
  • Any validation errors?
  • What time did it come in?
📬
Queue Layer

Check Queue Logs

  • Did the message enter the queue?
  • Is the queue growing (stuck)?
  • Was the message picked up?
  • Any dead-letter queue entries?
🗄️
Database Layer

Check DB Records

  • Does the TXN ID exist?
  • What is the status field?
  • Was balance updated?
  • What timestamp was recorded?
06 Real L2 Scenarios
01

Client says: "Customer paid but money didn't reach us." You check the DB — transaction shows SUCCESS. Balance updated. This means the money did move. The issue is likely a reporting or notification problem, not a payment problem. Completely different investigation.

02

Client says: "Payments are very slow today." You check the queue — it has 8,000 messages waiting and only 2 workers processing. The queue is backed up. Solution: scale up the number of workers or find out why they slowed down.

03

Client says: "Payment failed but customer's account was debited." This is the worst scenario. Money left the customer but didn't arrive. You trace both sides — check your DB and ask the bank. This is called a reconciliation mismatch and gets escalated to L3 immediately.

04

API is returning 500 errors for all payment requests. No need to trace further — the issue is at the very first step. Check the API server logs, check if the server is overloaded or if a recent deployment broke something.

✅ Day 5 Outcomes — Can You Do This?