[System Design] Transfer Sum

LiveRunGrow
4 min readSep 11, 2023
Photo by Aditya Vyas on Unsplash

Problem Description

We’d like to put up a counter of how much money has been transferred through the money-exchange APP in the past week. The purpose is to help customers trust us by showing how much volume we’re moving successfully.

Step 1: Gather Requirements

First, we need to ask the interviewer some questions to clarify the requirements. Lets imagine the answers to those questions are in italics.

Functional

  • What currency should the volume be expressed in? It should be in the local currency of the user. If they’re from a US IP address, let’s give them that value in USD. If they are from France, display in Euros.
  • What exchange rate to use? During time of transaction or when the APP page is loaded? Up to you.
  • What is the data source? There is a Transfer Service which will produce an event whenever a transfer has been sent out, and how mich and in what currency. There is a rate service which you can use.

Non Functional

  • How long should we store the data for? Can we purge data that exist for more than 1 week? Yes, don’t need to store data for more than 1 week.
  • What is the expected writes and reads? More writes than read.
  • How accurate does the data need to be? What if there is some time lag? Does not need to be accurate to the second. Can have some lag.

Step 2: Storage schema

The Transfer Service will emit an event for each transfer.

{
"currency": "SGD",
"amount": "488",
"timestamp" "21st Jan 2023",
}

More on how we will track the sum later below.

Step 3: High level design

Kafka

Each Transfer Service Event is sent to Kafka for durability and reliability of handling many Transfer events.

Service for computing the sum of transfers

We will have a service that will consume messages from Kafka and add the value of the transfer to the current sum, which can be a value stored in cache (for…

--

--

LiveRunGrow

𓆉︎ 𝙳𝚛𝚎𝚊𝚖𝚎𝚛 🪴𝙲𝚛𝚎𝚊𝚝𝚘𝚛 👩‍💻𝚂𝚘𝚏𝚝𝚠𝚊𝚛𝚎 𝚎𝚗𝚐𝚒𝚗𝚎𝚎𝚛 ☻ I write & reflect weekly about software engineering, my life and books. Ŧ๏ɭɭ๏ฬ ๓є!