In this more challenging coding challenge, you'll be tasked with building a simple real-time data pipeline simulator using TypeScript and Node.js.
You'll simulate a real-time data pipeline that consists of three main components:
- Data Producer: Generates random sales transactions at a set interval.
- Data Buffer: Acts as a buffer (queue) that stores the incoming transactions temporarily.
- Data Consumer: Pulls transactions from the buffer, processes the data to calculate real-time metrics, and logs those metrics.
- Generates a random sales transaction every 1-3 seconds. Each transaction should have a unique
id
,product
, andamount
.- product types are randomly
['apple','banana','strawberry','grape','pineapple']
- amounts are constraint from 1 to 10
- product types are randomly
- Stores incoming transactions from the Data Producer in a queue (FIFO).
- Should have a maximum size and drop the oldest transactions if the buffer is full.
- Processes transactions from the Data Buffer at a set interval.
- Calculates and logs metrics such as the total number of transactions processed, total sales, and total sales per product.
- Creates instances of the Data Producer, Data Buffer, and Data Consumer.
- Manages the interactions between these components.
- Logs any errors or dropped transactions.
- Use native TypeScript/Node.js features and data structures. You can use
setTimeout
orsetInterval
for time-based operations. - Make the Data Buffer size and processing intervals configurable.
- Implement proper error handling.
- Your code should be clean, modular, use classes where possible, and well-commented.
- Make the Data Producer emit transactions with random timestamps from the last 30 minutes, and have the Data Consumer calculate time-based metrics (e.g., sales in the last 5, 10, 15 minutes).
- Implement unit tests for your components.
You can choose to implement this in a single TypeScript file or break it down into multiple files/classes/modules as you see fit.
How would you optimize these queries? Answer when you turn in your assignment via email
1.
SELECT t.*, b.balance
FROM transfers t
JOIN balance b ON t."toAddress" = b.walletAddress
WHERE b.balance > 1000
AND t.contractAddress = 'some_contract_address';
2.
SELECT DISTINCT "toAddress", contract_address
FROM transfers
WHERE contract_address IN ('address1', 'address2', 'address3');