QR (quick response code) is a machine-readable 2-dimensional barcode consisting of an array of black and white squares, typically used for storing URLs or other information for reading by the camera on a reader e.g smartphone devices.
Let’s start with building a simpler version of the QR code payment transaction system. There are two types of users in our system: 1) Sellers 2) Buyers (Customers).
The system should allow these basic use cases:
We need to store data about sellers of a grocery store, their wallets, and transactions, buyers, wallet, and buyers' transactions.
A straightforward approach for storing the above schema would be to use an RDBMS like MySQL since we require joins. But relational databases come with their challenges, especially when we need to scale them. For details, please take a look at SQL vs. NoSQL.
The number of sellers is significantly less than that of buyers. Let’s assume:
Size of transaction table to store 10 year data = 200GB*365*10 = 730TB
Size of buyers table is 500M (total users)* 1KB (data per user)= 500GB total.
APIs for Seller Application
APIs for the Buyer Application side
Buyers and Sellers would use a relational database schema. We would use a payment gateway to transfer fund to or from buyers' bank account. We would also use a saga pattern for the distributed payment transaction.
We would use the saga pattern here. A saga is a sequence of local transactions where each transaction updates data within a single service.
Service on Docker and Docker on PODS: The number of requests to the system gradually increases over time. As the traffic increases even during peak hours like evening/morning, we need to handle additional traffic using auto-scaling by adding docker automatically based on CPU usage threshold or just traffic at each server’s load balancer level.
Load balancers: we would use load balancers at each key service to distribute traffic using the least conns strategy.
Sharding the database: if we shard the data based on the buyer’s id, then we can keep all transactions of a user in the same shard. But as the size of the transaction table is much larger than that of the user’s data table, therefore, we can choose to shard the data based on transactionId which can be integer incremented value based on timestamp. This is more useful as we can retrieve transaction data from any user from a specific shard just by looking at the timestamp range of the request.
Enjoy learning, Enjoy system design!
Whenever we build any Web Application dealing with real-time data, we need to consider delivering data to the Client. While building such a Web Application type, one needs to consider the best delivery mechanism, right! We are presenting a series of three concept blogs focusing on data transfer between clients and servers. In this blog, we are focusing on Server-Sent Events, and here, we will give you a complete insight into its internal working and the underlying features.
Instagram is a photo and video-sharing social media platform that allows users to share their creations with others. The original poster can set the visibility of these posts (photos/videos) to private or public. Posts can be liked and commented on by users. Users can follow and see the news feeds of other users (a collection of posts from the users they are following).
A web crawler (also known as a spider) is a system for downloading, storing, and analyzing web pages. Web crawlers are used for a wide variety of purposes. Most prominently, they are one of the main components of web search engines, systems that compile a collection of web pages, index it, and allow users to issue index queries and find web pages that match queries.
A load balancer is a software or a hardware device that sits between clients and a set of servers and basically has a balancing workload across resources. Not only do load balancers save our server or multiple servers from overloading, but it also increases the throughput of your system.
Twitter is a social media platform where users may post and interact with “tweets.” Users submit and engage with “tweets” on Twitter, a microblogging and social networking site. Users can subscribe to other users’ feeds and receive tweet notifications from those they follow. Tweets are almost 140–280 character communications.
Subscribe to get free weekly content on data structure and algorithms, machine learning, system design, oops and math. enjoy learning!