Thursday, June 29, 2017

Today we continue discussing another System Design question. We have been covering data architectures and store services. We were reviewing Payment Systems from Airbnb. Airbnb is a global onlinemarketplace where payments are one of the largest in-house payment systems. They had three standalone systems - a backend billing API, a payment gateway to external processors,  and  a financial pipeline for Spark based financial reporting. The platform events from billing and the payment events from gateway flow to the pipeline via Kafka. Billing interface allowed addition of items other than the usual reservation and payment which includes reservation nights, fees, taxes, photography costs, coupons by representing them with abstract data models and attributes. The checkout flow now becomes general to all items and streamlined while publishing events to all interested subscribers.
At AirBnb, cash payments is common practice, so they developed reservation statuses as well as a timer to both parties. Their payment platform implements asynchronous payments which enables new payment methods to be added for different countries. The payment events have a well defined schema and flow through Kafka.
They developed a Spark and Scala based financial reporting application. This financial data pipeline system replaces the SQL based reporting system with the added benefits that it is easier to debug, maintain and extend than the legacy system and can scale horizontally.  If we contrast this with the SQL Server on a Windows failover cluster as a high availability solution, then we see that we have added costs of a shared storage such as SAN. That shared storage allows the SQL Server instance to move to any other node since there is only one instance of the data. This was helpful if a host bus adapter failed or if the distributed transaction co-ordinator was to be failed over as well.
#codingexercise
Check if a subset of an array has a sum divisible by K
bool HasSubsetDivByK(List<int>A, int K)
{
if (A.Count > m) return true;
var dp = new bool[K];
for (int i = 0; i < A.Count; i++)
{
 if (dp[0]) return true;
 var n = new bool[k];
 for (int j = 0; j < m; j++)
 {
   if (dp[j] == true &&
    if (dp[(j + A[i]) % m] == false)
  {
        n[(j+A[i]) % m] = true;
   }
 }

 for (int j = 0; j < m; j++)
 {
   if (n[j])
       dp[j] = true;
 }
 dp[A[i]%j] = true;
}
return dp[0];
}
The same code above works for both positive and negative integers.

No comments:

Post a Comment