For the database, alternatively one could use columnar database, which enables fast aggregation and a have good storage size (due to the nature of columnar db). You'll partition the phone calls by month, and then order it by phone number and date time. And additionally if the fee is different for different time of the day, you can compute the cost on each call and save it there. This will enable generating the bill real time, which is useful to avoid heavy compute workload and enables user to see the bill before end of the month
What about using eventual cosistency here? I mean, some sort of data streaming like kafka to process all calls from customers so you can scale if needed depending on the producer/consumers. Consumers can basically process each call and add it to another database using MySQL (or RDBMS) to easily aggregate the calls by month (or billing period). I decide to use Kafka since the same topic can be used for another consumer to, let's say, analytics for the customer or even the company. I think having a single entry point of processing call, may become a bottle neck.
You wouldn’t want to use a queue. You would want an event streaming bus like Kafka . Kafka will retain the message if failures happen. A plain queue will not. I’m also assuming he is crunching aggregations on each customer at the end of the month. He will have to do so for each number associated with a customer. It can be quick or brutal depending a customer being a big corporations. We need a daily aggregator to insert updated keys in a key store with number hashed -> billing numbers. He then would check for phone numbers. In each service as it aggregates a much easier additive number. Once bills are calculated a notification to the user via a queue. It can broad cast to all comm services
29:20 I like how he handles the data mining and parallel processing more easily by sharding, and the billing service is sharded too to match it , so each worker can split the shards
To me, this is not a good design. Some improvements I have in mind:1) A phone bill is created for each individual phone number, not for individual customer, so partition key could be different. 2) Calls are bounced between different phone operators, caller's operator does the billing but sometimes the fee is calculated based on the operator on the other side of the call. Fees also differ on different days and hours, so there is no single fee per call duration. 3) Bills do not need to be calculated at the end of the billing period, Computation task can be done after each call is made, then the billing service just needs to aggravate the already computed date. This will free up the computing bottleneck. This also allows us to not store every call information on the live database, which will grow huge. We just need to store the billable calls that is not gone through the billing job, any other call or the computed calls can move to a cold archive db immediately. So, my design would be a queue consumer that computes the feee after each call and moves the call data to the archive db and inserts the fee per call in a temporary db, and a map-reduce job run at the end of the billing period to aggregate the computed data into a bill, and remove the call fee data from the temporary db.
@@mohammadtoficmohammad3594 Who's your 'dear'? I'm suggesting a different design if you read it full. You should do more than that if you're to design a system or pass an interview to the least.
Great feedback and valid points, kdakan! Please consider this video an example of how to approach an interview design problem in a structured manner leveraging the background, domain knowledge, and ideas you bring to the interview on that day rather than the incontrovertibly best possible answer to this particular question. I'd encourage viewers to consider my design critically and contribute ideas here on how it could or should be improved (or even make your own video!).
kdakan your design is not good , we can not calculate the bill after each call , thats will be huge load on the system , to call the temp database , save the result in temp db ,move old data to archive db , delete the old from the tmp db , all that on every call.
Great stuff. I'd say though using off the bat integration via shared database tightly couples Call Control Framework with the Billing Service, it is often being frowned upon. There are benefits for such integration: in case Billing Service generates bills once a month, Call Control Framework guys have a chance to fix records before bill is generated. Though I would seriously consider queueing data.
I really liked how well Tim introduced each component whilst stating the responsibility, and then stitching them all together. Great video! What software/app do you use for drawing?
for the orchestrator I would imagine we have Apache Airflow that spawns worker processes that would create nodes in a Apache spark cluster to aggregate the data and that would then be sent to the billing DB with aggregation. would that be a good approach rather than use orchestrator and workers? Be more specific on tools we could try using in this distributed system
Get 1-on-1 system design interview coaching from Tim or other ex-FAANG interviewers: igotanoffer.com/en/interview-coaching/type/system-design-interview?TH-cam&
For the database, alternatively one could use columnar database, which enables fast aggregation and a have good storage size (due to the nature of columnar db).
You'll partition the phone calls by month, and then order it by phone number and date time.
And additionally if the fee is different for different time of the day, you can compute the cost on each call and save it there.
This will enable generating the bill real time, which is useful to avoid heavy compute workload and enables user to see the bill before end of the month
What about using eventual cosistency here? I mean, some sort of data streaming like kafka to process all calls from customers so you can scale if needed depending on the producer/consumers. Consumers can basically process each call and add it to another database using MySQL (or RDBMS) to easily aggregate the calls by month (or billing period).
I decide to use Kafka since the same topic can be used for another consumer to, let's say, analytics for the customer or even the company.
I think having a single entry point of processing call, may become a bottle neck.
If there are 500M calls per day, I think we would expect around 15B calls per month instead of 1.5.
You wouldn’t want to use a queue. You would want an event streaming bus like Kafka . Kafka will retain the message if failures happen. A plain queue will not. I’m also assuming he is crunching aggregations on each customer at the end of the month. He will have to do so for each number associated with a customer. It can be quick or brutal depending a customer being a big corporations. We need a daily aggregator to insert updated keys in a key store with number hashed -> billing numbers. He then would check for phone numbers. In each service as it aggregates a much easier additive number. Once bills are calculated a notification to the user via a queue. It can broad cast to all comm services
Good to know that I see this message on a similar approach I suggested!
29:20 I like how he handles the data mining and parallel processing more easily by sharding, and the billing service is sharded too to match it , so each worker can split the shards
To me, this is not a good design. Some improvements I have in mind:1) A phone bill is created for each individual phone number, not for individual customer, so partition key could be different. 2) Calls are bounced between different phone operators, caller's operator does the billing but sometimes the fee is calculated based on the operator on the other side of the call. Fees also differ on different days and hours, so there is no single fee per call duration. 3) Bills do not need to be calculated at the end of the billing period, Computation task can be done after each call is made, then the billing service just needs to aggravate the already computed date. This will free up the computing bottleneck. This also allows us to not store every call information on the live database, which will grow huge. We just need to store the billable calls that is not gone through the billing job, any other call or the computed calls can move to a cold archive db immediately. So, my design would be a queue consumer that computes the feee after each call and moves the call data to the archive db and inserts the fee per call in a temporary db, and a map-reduce job run at the end of the billing period to aggregate the computed data into a bill, and remove the call fee data from the temporary db.
@@mohammadtoficmohammad3594 Who's your 'dear'? I'm suggesting a different design if you read it full. You should do more than that if you're to design a system or pass an interview to the least.
Great feedback and valid points, kdakan! Please consider this video an example of how to approach an interview design problem in a structured manner leveraging the background, domain knowledge, and ideas you bring to the interview on that day rather than the incontrovertibly best possible answer to this particular question. I'd encourage viewers to consider my design critically and contribute ideas here on how it could or should be improved (or even make your own video!).
@@loinsrch I understand this is a new channel and these videos are somewhat geared towards engagement from viewers. Thanks for the info.
@kdakan totally agree, I was thinking in the same direction of using queues, hadoop/spark map-reduce jobs etc which looks a good fit for this case
kdakan your design is not good , we can not calculate the bill after each call , thats will be huge load on the system , to call the temp database , save the result in temp db ,move old data to archive db , delete the old from the tmp db , all that on every call.
Great stuff. I'd say though using off the bat integration via shared database tightly couples Call Control Framework with the Billing Service, it is often being frowned upon. There are benefits for such integration: in case Billing Service generates bills once a month, Call Control Framework guys have a chance to fix records before bill is generated. Though I would seriously consider queueing data.
I really liked how well Tim introduced each component whilst stating the responsibility, and then stitching them all together. Great video! What software/app do you use for drawing?
thanks very useful video and good software design
Thanks Mohammad, glad you like the video.
for the orchestrator I would imagine we have Apache Airflow that spawns worker processes that would create nodes in a Apache spark cluster to aggregate the data and that would then be sent to the billing DB with aggregation. would that be a good approach rather than use orchestrator and workers? Be more specific on tools we could try using in this distributed system
Which tool are you using to do the system design on?
If I remember rightly, Tim's using Excalidraw :)
Get 1-on-1 system design interview coaching from Tim or other ex-FAANG interviewers: igotanoffer.com/en/interview-coaching/type/system-design-interview?TH-cam&