☕ Facebook vs. Visa?

A System Design Interview Question. Facebook opensources FastPay, an RTGS System that Facebook is using for their Novi Project. Slack talks about how they built a logging system in React.

Hey Guys,

Hope you’re all having a fantastic day!

Let’s get to the Interview Question, Daily News and Previous Solution!

Interview Question

What are Peer to Peer networks?

In what kind of scenarios do they come in handy for System Design?

Can you give an example of a system where you might use a Peer to Peer network?

We’ll send a detailed solution tomorrow, so make sure you move our emails to primary, so you don’t miss them!

Gmail users—move us to your primary inbox

  • On your phone? Hit the 3 dots at top right corner, click "Move to" then "Primary"

  • On desktop? Back out of this email then drag and drop this email into the "Primary" tab near the top left of your screen

Apple mail users—tap on our email address at the top of this email (next to "From:" on mobile) and click “Add to VIPs”

Industry News

Facebook open-sources FastPay, an RTGS System built in Rust for their Novi Cryptocurrency Project

FastPay is a Real Time Gross Settlement (RTGS) System that Facebook has built as a demo for their Novi cryptocurrency project. An RTGS System is a system that handles the transfer of payments from one account to another in a way that is

  1. Instantaneous (Real Time)

  2. Complete (the entire amount is transferred - Gross)

  3. Final and Irrevocable (Settlement)

Facebook has built such a system in Rust, called FastPay.

The system is distributed and Byzantine Fault Tolerant. This means that nodes in the system can fail (and there is imperfect information about which nodes have failed) but the system can continue to perform reliably. FastPay can tolerate up to x Byzantine Failures out of a total of 3x + 1 authorities and still retain high performance.

FastPay is also highly scalable. This is where many traditional blockchain based payment systems are criticized. FastPay can achieve confirmation is less than 100 milliseconds and can handle over 80,000 transactions per second. This would result in a network that is 7 times faster than Visa.

Slack’s React Analytics Logging Library

Slack has gone into detail about how they’re building their Analytics Logging Library for their Desktop Application. They go into interesting detail about how they used

  • React’s Context API - easy way to pass around your props between components without “prop-drilling”

  • Intersection Observer API - way to get notifications when a user’s viewport intersects with an element in your HTML.

The new library helped Slack achieve a 66% decrease in log code length and allows devs to implement logging in a quarter of the time.

Previous Solution

As a reminder, here’s the previous question

Given a positive integer n, build a square matrix that has elements from 1 to n^2 in spiral order.

Example

Input - 3

Output -

[

[ 1, 2, 3 ],

[ 8, 9, 4 ],

[ 7, 6, 5 ]

]

Solution

We can break this problem down into two parts.

The first part is to build the n x n matrix and get all the numbers from 1 to n^2

The second part is to iterate through the matrix in spiral order and iteratively set each item in the matrix to the corresponding number in our array from 1 to n^2.

In order to iterate through the matrix in spiral order, we create four pointers: top, bottom, left and right.

top points at the top row and bottom points at the last row.

left points at the first column and right points at the last column.

Then, we create a while loop that runs while top <= bottom and left <= right.

On each iteration of the while loop, we iterate through one row or column in one of the four possible directions. Based off how “spiral movement” works, the directions go in the order

  1. left to right

  2. top to bottom

  3. right to left

  4. bottom to top

We use a counter to keep track of which direction we’re going in.

At the end of each iteration of the while loop, we increment the counter (unless the counter is at direction 4, in which case we set it back to direction 1).

Best,

Arpan