darkua / json_delta

a service that tracks json model changes and lists them
0 stars 0 forks source link

Filter by date #1

Open donbonifacio opened 7 years ago

donbonifacio commented 7 years ago

Hello,

Thanks for making our challenge! It's always interesting to see new approaches to the problem and to learn from it. :)

Now the team will leave some questions and provide some feedback. Here is my first one. To filter by the dates, you do:

return _.filter(elements, function(item) {
    return item._timestamp >= startDate && item._timestamp < endDate
})

Imagine that elements is a very huge collection. How could you replace this loop for something faster?

What are the implications of having a CPU heavy operation like that on a request? What would happen to the server?

darkua commented 7 years ago

Hello Pedro, yes there is definitely space to do some optimisations to the code relative to time/space complexity. I used a simple array for simplicity, but since we want to find a collection of data points in a interval, a BST, range tree would do the job quicker, according to wiki O(n log n) :)

The implications of this are requests taking to long to reply, blocking server to handle other requests and with a worker pool in place without a decent backoff retry, will melt and crash the server, been there done that :)

donbonifacio commented 7 years ago

Well, you and me both! :) That were the responses I was looking for.

Would you consider replacing a CPU intensive job in node for some other tech?