Latest / Agentic Conversations (formally mlops.community) / Real-time Feature Generation at Lyft // Rakesh Kumar // #334
Transcript
- 0:00Some of them are like precursor as well.
- 0:02So when we initially introduced the pipeline, right, we were
- 0:07able to cut down almost like 60% of the code base.
- 0:11Wow. So I'm Rakesh and senior staff
- 0:19engineer at Lyft and I like Latte.
- 0:24We recently had your colleague Josh on here and he was talking
- 0:29a lot about the data science side, the algorithms, the
- 0:34modelling side of things. Now you're coming from the
- 0:37engineering side and we get to talk to you about real time
- 0:42machine learning, which is everyone's favorite topic I
- 0:46think because it is so hard to get right and you all have been
- 0:52getting it right for a while. Maybe we can break down first.
- 0:55What do you do in real time machine learning use cases with
- 1:00at Lift for? So, real time use case.
- 1:04A real time machine learning features mention use cases.
- 1:06They cover most of the critical business use cases.
- 1:09And that's a mouthful. So I will bake it down.
- 1:13So what we do is we try to process real time data that is
- 1:20coming from the users, devices, various services.
- 1:24We get those data, we process that data and we transform the
- 1:28data, we aggregate the data and then we pass it down to our
- 1:33machine learning model. And these machine learning
- 1:36models are basically powering some of the use cases.
- 1:40One good example which was covered earlier in in the
- 1:43podcast that was real time forecasting.
- 1:46So for any region or any city, any venue, we want to forecast,
- 1:52you know what will be the demand, what will be the supply
- 1:55at any specific time. So that is 1 use case.
- 1:57The other use case is search prices.
- 2:00That means we want, we generally monitor marketplace for any city
- 2:06and if there is any kind of imbalance in demand and supply,
- 2:10we want to accordingly adjust the prices.
- 2:13For example, if there's less number of driver in that area,
- 2:17we want to increase the prices so that like we slightly dampen
- 2:22the demand. Yeah.
- 2:23So that way like we are trying to adjust all those things.
- 2:26So these are two examples, but there are a couple of other
- 2:29examples as well. Yeah, and the hard part about
- 2:33this is the real time list to it, right?
- 2:36That adds a bunch of extra complexity if it's that online
- 2:42feature generation and then creating that model that can be
- 2:47making these predictions in real time.
- 2:49Right. So to just cover the full
- 2:52context in feature generation part, there are primary 21 is
- 2:57the offline generation and the other one is real time
- 2:59generation. In offline generation, you have
- 3:02the data, in offline data store you have time to you know
- 3:06process the data and generate the feature.
- 3:08You do not have that tight latency requirement, right?
- 3:12But in the real time, what happens is that like you need to
- 3:16process millions of data points in real time.
- 3:19That means it could be second to sub second latency requirement,
- 3:24right. So as you are getting the data,
- 3:26you are processing all these things and you have to provide
- 3:29that data as soon as possible to do all these real time machine
- 3:33learning model so they can make all these predictions.
- 3:36And it is very important for a Lyft to process all these behind
- 3:42real time. You do not want to serve still
- 3:44data to model because then your model will be drifting apart
- 3:48from the actual actually what is happening in in, in the world,
- 3:52right? Let's say you your model is like
- 3:56or your pipeline is slow by 30 minutes.
- 3:59It may not be accurately predicting the current market
- 4:01condition. You will be giving prices which
- 4:05are stale, which is old and whatever you're trying to do, it
- 4:09may not reflect correctly. So it's really important for us
- 4:13to basically process all these data really fast and just
- 4:17provide it to all these machine learning models.
- 4:20Yeah, you can potentially lose a lot of money for the business.
- 4:24And we had, we had seen that as well like in terms of latency,
- 4:31if we degrade our latency requirement or we take a longer
- 4:36time, it affects the performance of the model.
- 4:40Yeah. So it is very important we try
- 4:43to minimize the latency as much as possible and it could go to a
- 4:48second or sub seconds as well. Well, I want to talk about some
- 4:53tricks that you've done to make sure that latency is as low as
- 4:58possible. If I am understanding it
- 5:02correctly, when you say real time, you're one of the few
- 5:05people that mean real real real time.
- 5:08It is not. It's like a 5 minute window real
- 5:12time. It's more half a second type of
- 5:15real time. So I, I think that you had a
- 5:18kind of a really good question. What is real time, right?
- 5:21Different people have a different definition about the
- 5:24real time. Sometimes people say synchronous
- 5:27call is real time, some people say you know asynchronous
- 5:30processing but in real time that is it real time.
- 5:33So for this talk we are talking about the async processing like
- 5:39we are not talking about scenarios but for this specific
- 5:43talk we will be talking mainly about the async processing.
- 5:46So and there also there are a couple of what do you call it
- 5:51use cases. You mentioned about 5 minute
- 5:55window, one minute window we do do that as well.
- 5:59It completely depends on the the use case, right.
- 6:04For forecasting use case we have aggregate like we aggregate data
- 6:08for one minute window and five minute window as well.
- 6:11And then we providing to them. In some cases we also have a
- 6:16short term historical data and then we provide it to them.
- 6:19So it completely depends on the use case.
- 6:22Most of our use cases are based on one minute aggregated data.
- 6:27That's how our models are designed and that's how or
- 6:31that's our that's how the pipeline are supposed to provide
- 6:34that data to to the models. So it is not the extreme side
- 6:40where like it is you know sub second or so or like when you're
- 6:44when you're talking about a synchronous call, it's more
- 6:46about the asynchronous processing of the data.
- 6:50Is it like the complexity and the difficulty increases
- 6:57exponentially if you're going from that 5 minute real time to
- 7:03one minute real time? Or is it something where you can
- 7:08create a system and once it's in place, you can get to a certain
- 7:14point where you've got that cushion and whether it's 10
- 7:19minutes or it's one minute, you're good, but you start
- 7:22hitting the ceiling. If you're starting to talk about
- 7:24the sub second latency, like I'm trying to gauge how different it
- 7:30is to be at 5 minute real time versus one minute real time
- 7:34versus millisecond real time. So if you go further like if
- 7:40you're trying to look at the sub second latency and you're
- 7:44comparing with the synchronous processing, it is not the case
- 7:47there. It is like most of the cases
- 7:51asynchronous call is really with one's request.
- 7:55But our processing is based on the aggregated data.
- 7:58That means we are getting all these data from different
- 8:00sources and we are trying to aggregate them based on the
- 8:04geohashes. So geohashes is a size of a city
- 8:07block or so. So like and you can imagine like
- 8:11we are getting this data from different cities across
- 8:15different nations, you know, and then we are trying to process
- 8:19that data and then we are processing the data and then we
- 8:24have to go to the city level block and aggregate the data.
- 8:29Coming back to your question, like where is the nice cushion?
- 8:34I would say it depends, it depends on the use case and the
- 8:38data volume that we are trying to process it.
- 8:41I would say if it is smaller window, it's much easier to
- 8:46aggravate because you are accumulating less data and you
- 8:50can you know, emit the data faster.
- 8:53But if you have a longer window, that means you are connecting
- 8:58that data in memory for a longer time and then you're emitting
- 9:02that data. So you're processing and what do
- 9:06you call the memory utilization increase significantly.
- 9:10And we had seen use cases where we tried to do 30 minutes
- 9:14aggregation. It was working, but it was not
- 9:18scalable. And yeah.
- 9:20Got expensive? Yeah.
- 9:22So one minute or five minute, those are pretty good and good
- 9:27use cases. Now, can you walk me through a
- 9:31bit of the evolution of how you've tackled this specific
- 9:38problem, the real time problem while being at Lyft?
- 9:42Because I feel like you've been through different iterations.
- 9:46I will divide this value evolution in two or three
- 9:50phases. First phase, like when we were
- 9:54very early phase, when we were not even using all these
- 9:58streaming engines to process all these data, what we had at that
- 10:02time was Cron job based processing.
- 10:06So it will get up at the top of the minute.
- 10:09It will try to get all these data from the Kinesis processes,
- 10:14store it in a kind of temporary location.
- 10:17Most likely that is then the next Cron job will get up.
- 10:20It will, it will process that data and that's put it and
- 10:24imagine every stamp is doing this processing the top of the
- 10:28minute. So even though the very first
- 10:31process, very first Cron job has finished, it starts within one
- 10:35or two seconds. The next one is not going to
- 10:37start immediately. It will take a lot longer.
- 10:40It it was working but like as we are growing it was not a kind of
- 10:45a scalable solution. Our models were not also
- 10:48performing well because inherently the system has
- 10:52latency. So what we try to do is like OK,
- 10:55since our model will not perform better, like if there is
- 10:58inherent latency, we want to reduce it.
- 11:00So we research on like what are technologies are, how we can re
- 11:04architect the solution and we after our research, we realized
- 11:10that we can use some streaming based solutions which can
- 11:13process this data. And there you do not need to
- 11:16wait it wait for the next step to get triggered at specific
- 11:20time in the stream processing. As soon as the very first
- 11:24operator has processed the data, it will send it to the next
- 11:27operator or next operator downstream and it will process
- 11:31it. So it's more about like when the
- 11:33data is available, it will process, it does not have to
- 11:35wait there. So initially.
- 11:39In this you're talking about like Flink, right?
- 11:41Right, so and we use Apache Beam and Apache Beam is using a Flink
- 11:48underneath. We initially did Apoc and
- 11:54initial results were great, like it worked fine.
- 11:57We also choose Apache Beam Python as the game, mainly
- 12:00because we are Python shop. Most of our services are written
- 12:03in Python. People are comfortable in Python
- 12:06And you know, our models are written in Python.
- 12:08So we'll start. OK, maybe we'll just use it.
- 12:10The interesting thing is that though Apache Beam is in like we
- 12:17we are using Apache Beam Python SDK, but it is doing most of the
- 12:21processing in the Apache Flink and Flink is JBM based
- 12:26technology. Yeah.
- 12:28So it, it was a good, you know, hybrid solution and we used it
- 12:32for what we call real time search pricing or or prime time.
- 12:40And it was, it was good when we launched it for one or two
- 12:44reason, regions or cities. But when we started scaling it
- 12:48out, then we realized that, OK, this is not going to scale
- 12:53because the way we were processing it, our data, it was
- 12:57not very performant, mainly because we were doing most of
- 13:02the processing in one operator. That was 1 issue that was easy
- 13:07to fix it. You divide the operator, it is
- 13:10perfect, right? It was right.
- 13:13Then we hit the other problem where you know what happened is
- 13:18that even though we separated out the processes, it was
- 13:22processing it. Then we realized that some of
- 13:25the nodes are like, you know, 90% CPU relation.
- 13:29Some of them were not even doing anything.
- 13:31It was like 10%. And the problem is how we, like
- 13:35most of our cities are, I would say the traffic is divided based
- 13:40on the cities. That's how our models process
- 13:42all these things, right? And what we were doing is that
- 13:46we were routing all the traffic from a specific city to one
- 13:51particular Shard or one particular node.
- 13:54And some of our top cities are of course right in New York, San
- 13:59Francisco and all those things. They have almost 80% of the
- 14:03traffic. So now imagine that 80% is going
- 14:06to one node and the rest of the other are going to other nodes.
- 14:09That was a really classic, you know, heart shot issue.
- 14:13And we look, oh, OK. And that's interesting.
- 14:16The distribution here is not adding up, yeah, so.
- 14:22Then we realized that we we are not using it perfectly.
- 14:25What we need to do is we need to divide that further processing
- 14:30you. What you do is instead of city,
- 14:33you divide in terms of Geo hashes.
- 14:35Geo hashes again, there's a city block.
- 14:39So what we do is as soon as we get the data, we say, OK, what
- 14:43is the Geo hash for this particular event?
- 14:45And then we started based on that one.
- 14:47So from, you know, from you know 300 plus series then it further
- 14:54translated into almost millions of Geo hashes.
- 14:58So and these Geo hashes are almost uniformly distributed
- 15:02across different nodes. So in a way like we, we are not
- 15:05running into any kind of hot chart issue that the load is
- 15:08uniformly distributed across different nodes.
- 15:12And once most of the data processing is done, most of the
- 15:16heavy computation is done then and this how you competition is
- 15:20like, you know, filtering those data, aggregating it and any way
- 15:23we wanted all these aggregated data based on the geohash then.
- 15:27And once that is processed, you have one number and then the
- 15:31geohash. So it comes down to a very small
- 15:34data set that you can again recharted to region and that's
- 15:39how like one region can get all the relevant geohashes.
- 15:43So effectively it's small data and that does not run into any
- 15:47kind of hard shooting issue. Those bottlenecks aren't there
- 15:53now. I feel like I've talked to
- 15:57somebody at Lyft before. It wasn't on the podcast
- 15:59specifically, but they were in the community and they were
- 16:03mentioning how having to create different configs for each of
- 16:11the setups that they had ended up driving them nuts.
- 16:16And I think they ended up going and creating a company around
- 16:19it. But as you're talking about this
- 16:22and you're saying, hey, we've got all of these different
- 16:25models they're pulling in, or we've got all these different
- 16:27nodes, they're pulling in the geohashes.
- 16:30And then you also have the different clouds that you're on
- 16:33and you have the different regions that you're playing with
- 16:37there. Is that something that you
- 16:40looked at and that was affecting you?
- 16:43Also when it comes to having to figure out the config on this
- 16:50model or this node or this Geohash, I'm not sure how you,
- 16:55how you broke it down is with this region and it's got the,
- 17:00these things that we need to be aware of because are you running
- 17:04just thousands of models across the world or hundreds of
- 17:09thousands? I I don't know what what that
- 17:11looks like and how that works. So most of the real time
- 17:16processing in that case we use model per region.
- 17:22And so that is like one simply simplistic simple view of the
- 17:27world. But that could be also further
- 17:31divided into sub regions like and there's a couple of use
- 17:36cases there. So and like if you, let's say
- 17:41San Francisco, it's a big city like and sometime if you're
- 17:46trying to process the data and trying to give it to 1 model, it
- 17:48may not be performed accurately right in different parameters.
- 17:54So what do you want to do is like you want to divide that
- 17:56region into sub regions. So that way you independently
- 18:00process all these regions. There are trade-offs there, but
- 18:03at least on like if you are breaking down to a smaller
- 18:07region, it's much easier to manage them.
- 18:10So that's how like we used to do.
- 18:12So earlier we were processing the region level.
- 18:15Now in some of the use cases we have broken down into sub region
- 18:19level and that's how we process it.
- 18:21But on the pipeline side we are still doing on Geo hashes.
- 18:26We are processing Geo hashes and it it does not matter like how
- 18:32you consume it, we can always transform that data either to
- 18:35sub region level or region level.
- 18:37Of course, like the our customers, they define how they
- 18:41want to consume the data and it's quite easy to just
- 18:44transform the data and then provided.
- 18:46And in a way it's much better for us that we further divide
- 18:50that region into smaller chunks. So that way we do not run into a
- 18:55hard shot issues as well. I like how you mentioned there
- 18:58that our customers, I'm assuming that's like Josh who I spoke
- 19:03with a few weeks ago, that's the data scientist.
- 19:06They get to define how they want that data, how often they want
- 19:10that data, all of that type of thing.
- 19:12And I think the fancy word for that these days is a data
- 19:16contract. You all have put into place a
- 19:19data contract. You have the producer of the
- 19:21data and then the consumer of the data.
- 19:23And you're able to stay accountable so that if you're
- 19:29changing anything with that data, Josh is in the loop.
- 19:33Or if Josh needs anything changed, then you're in the
- 19:36loop. And I wonder how you got to that
- 19:41point. So how we got it to that point?
- 19:46So what we generally do, there are two strategy that we use.
- 19:51In one case it is like off the shelf, you can use that pipeline
- 19:55generate feature by by yourself and most of the cases they are
- 20:01very simple aggregation. But in case where you have very
- 20:06specialized need and some complicated business logic, in
- 20:11that case we hold their hand and say that you provide me the
- 20:15contract, I will build the future for you.
- 20:19And we like they generally what happens they, they create the
- 20:24data from the offline data stores.
- 20:27They create, come up with a query, they generate all these
- 20:30features in offline mode. That's their model.
- 20:32If everything is looking good, they say, OK, the performance is
- 20:35really looking good, I want to productionize it, I want to make
- 20:39it real time. That's when we come into play.
- 20:42And then say we convert that query into a pipeline
- 20:46implementation. So like we transform that query
- 20:50into a pipeline and our contract is generally that whatever
- 20:55features that you are able to compute using offline data, we
- 21:01will be able to match that data with almost 99.9% OK.
- 21:07And when we build this pipeline, we compare the real time feature
- 21:12with the offline 1 and make sure that it is closed and and.
- 21:17And this is also required because we have a tight SLA in
- 21:20terms of, you know, latency as well as the quality and we do
- 21:26not want to degrade on the quality.
- 21:28So we have another framework or in house framework which
- 21:34basically comparing the the real time feature and offline 1.
- 21:40Offline in the sense that it is a source of crude our ground Rd.
- 21:45we are comparing these two feature.
- 21:47We are basically sampling the real time feature and then the
- 21:50offline 1 ends and trying to compare like how different they
- 21:54are if they are. That's cool.
- 21:56Yeah, if it is, they are different than we.
- 22:00There's alert define for that one and it will trigger and then
- 22:02we we say why they are different.
- 22:04We, we are but, but most of our features or I would say all of
- 22:10the features that we generate on a real time feature platform, we
- 22:14have that kind of observability in place.
- 22:16So it's really the operationalizing of the feature
- 22:22pipelines. Yes, that's right.
- 22:24And so as a data scientist, they almost have it.
- 22:29They've got it good. They can just develop these
- 22:32feature pipelines offline and then throw you the shitstorm of
- 22:37making them real time. Yeah, it is, It is interesting.
- 22:44Yeah, like and then there, there are different consideration when
- 22:50we are transforming that offline query into a real time query.
- 22:56At the high level the results are same.
- 22:59But when you implemented, you have to also consider like how
- 23:02these pipelines are processing these data, how I can avoid the
- 23:06hard charting issues. And like there's a lot goes into
- 23:12while designing that pipeline. And some of our in house
- 23:17engineers, they are explored in this and then as soon as they
- 23:20get it, they query, they know like these are the parameters
- 23:22which are not looking good. We have to do a further
- 23:25processing. We have to further divide into
- 23:27based on the number of Geo hashes and make it process in
- 23:32such a way that it will not run into a kind of hard shaded show.
- 23:36Yeah. Now the obvious next question
- 23:41is, do you all have? Are you using some type of a
- 23:45feature store? We do use a feature store and
- 23:50most of the traditional feature store may not work for us,
- 23:54mainly because they are point feature point feature.
- 23:57That means you have a key, let's say I'm user, and then you have
- 24:00a value. So let's say when this user was
- 24:04onboarded, so you just provide a date, right?
- 24:07Or whether what is the city where this user or requested a
- 24:14ride something that this one's, it's very straightforward,
- 24:17right? So that is 1 use case.
- 24:19But the other use case where most of our models work, that is
- 24:25aggregated, right? We try to figure out whether
- 24:29there's an imbalance in the market and we do not look at the
- 24:33individual session, we look at the holistic view of that city
- 24:37or region. So we want to see how many
- 24:40drivers are there, how many requests are coming from that
- 24:43city, right? And in this case, like
- 24:46reconsider that city or geohashes, right?
- 24:49And we want to not get just the one point value.
- 24:53It's like the whole aggregated value and it is hierarchical.
- 24:57That means a city will have multiple G hashes and within the
- 25:01multiple G hashes as well like we have GH4GH5GH6 so and all of
- 25:06them are hierarchical. So regular feature store will
- 25:09not work. So what we did is like we create
- 25:12a geospatial based feature store there.
- 25:17If you provide a region, then I can provide you all the
- 25:23geohassets coming under that region and their aggregated
- 25:26value. And you can choose the level at
- 25:30which you want it like whether you wanted region level, whether
- 25:34you want the GH5 level, GH4 level, you just provide that.
- 25:38And then we can, we can just provide the data to you and, and
- 25:43it is interesting and it works and, and it was able to scale
- 25:47well as well. As I was saying earlier, some of
- 25:51our model, they work at region level.
- 25:52Some of them you know, at the sub region level.
- 25:56Some of them they work at, you know, Geohash level, AGH 4
- 25:59level. And the source of data is the
- 26:02same, but they can, they can consume it differently, they can
- 26:08ask for region level. We can still provide the region.
- 26:10It is the same data. It's just that the accessing
- 26:12mechanism is slightly different, but it has the same API.
- 26:16And that has helped us a lot. Like you know we can generate
- 26:20one feature and then this one feature can be shared by
- 26:23multiple models as well. How are you making these
- 26:28different layers of the geospatial data?
- 26:32What is that even look like under the hood to be able to
- 26:38serve up that type of offering on the?
- 26:41API, yeah. So it's based on the
- 26:44hierarchical. That means you have a region,
- 26:46then you have GH4GH5GH6. So region might have a couple of
- 26:52GH fours, GH fours may have a couple of GH fives and all.
- 26:57And it's hierarchical. It's basically a kind of a tree
- 27:01and when you're selecting anything like say you're
- 27:03selecting a region, you know all the nodes under that tree or
- 27:08leaves under on that. And then it's up to the the
- 27:12builder or the data scientist to decide how granular they want to
- 27:16get in this specific use case or for this specific model.
- 27:20Yeah, that's right. And like how we store the data,
- 27:24we generally store in two different ways.
- 27:26One is the region level, like we store the entire thing and then
- 27:29the rest of them we have divided into GH6 level and then we have
- 27:34defined the mapping between GH6 and GH5.
- 27:38So whenever someone sends us a request, we get the data from
- 27:43the store, aggregate them for them and just pass it to them.
- 27:47So it's it's basically when you look at the GH or Geohash the
- 27:55the prefix are I would say postfix are always matching the
- 28:00the latter part of the GSS is always matching.
- 28:04So if I give you AGS 6 and if I tell you to come give me the
- 28:09GH4, you're basically getting the let's substring of that one.
- 28:14So you're basically just getting the four character from the GS
- 28:186. And that's how you're able to do
- 28:20it. So it's it is very
- 28:22straightforward calculation. Now the other thing was around
- 28:27the offline and online piece, which I think it would be good
- 28:33to go into how it looks offline when folks are doing offline
- 28:40jobs versus online. And I, I think the online part
- 28:45is quite clear to me right now, but I want to know what do you
- 28:51do for offline? And also is offline just for
- 28:55that ground truth? Is it for different use cases
- 28:59that you're servicing? What is that?
- 29:03So offline, so most of our real time data and they end up in
- 29:08offline store for various reasons.
- 29:11One of the primary reason is that you know like you want to
- 29:14see historical data and when data scientist or MLA engineers
- 29:20are working, they want to see how the data looks like.
- 29:23They transform the data, they want to transform it and make it
- 29:27as feature and test out with that model.
- 29:31And this is what one example. The other example is like when
- 29:34we want to validate the real time feature whether they are
- 29:37accurate or not. Like that is another one as
- 29:40well. Sometimes we can also do back
- 29:43testing. That means if models misbehaved
- 29:45in production, you want to go and replay and saying like why
- 29:49they misbehave, you want to debug further.
- 29:51So there are a couple of use cases there, offline and online.
- 29:56I think offline world you get delayed data as well.
- 30:01You have like, you know you can have all the data and you have
- 30:05all the time to process it. But in real world or real time
- 30:09processing, it's difficult. If the data is delayed, we
- 30:13cannot wait forever for you to complete like and you do not
- 30:16have that much of time. So what happens there?
- 30:19Like you either just move fast, like you ignore that one and
- 30:23move fast and you process it. So that's how it happens.
- 30:26And earlier I was telling you that, you know, we have 99.9
- 30:30percentile or percent matching data, but why it's still there
- 30:35is a gap, why we are not able to match 100%?
- 30:39That is the reasons in, in real time data may be missing.
- 30:43It will not be delayed. Imagine person going through a
- 30:46tunnel, somehow they don't have a network and then the device is
- 30:50not able to send the data. And once they come to area where
- 30:53they have a nice signal, nice connectivity, the data is synced
- 30:57to the server. And that's how we get we get a
- 30:59kind of delayed data. Yeah.
- 31:02So one thing that I would love to get into though, is the the
- 31:14actual decisions that are being made in these meetings when you
- 31:20have to say, OK, we want to go and support XYZ, whatever XYZ.
- 31:27Maybe, maybe it is a new technology, maybe it is a new
- 31:31type of architecture or a new experiment where you're going to
- 31:36change the system. How are you all thinking through
- 31:40the trade-offs as you're thinking through these bigger
- 31:44decisions? Because I can only imagine that
- 31:48you're having your retros, you're also recognizing that
- 31:52you're supporting quite a large scale and you want to
- 31:56continuously be moving forward. You don't want to get stuck in
- 32:00time, but because you have to make certain decisions and
- 32:06create opinions, there are things that you're going to land
- 32:11on that potentially can be a couple year relationship or a
- 32:18decade long relationship with a certain technology or a certain
- 32:21system, right? So there are so many
- 32:24considerations go into this. Definitely one of the primary 1
- 32:32is that whether this technology is a good fit for this problem
- 32:37domain or not. It may be good fit right now,
- 32:41but down the line it may not be good fit.
- 32:45Things could change, traffic pattern could change, you know
- 32:49there's a new technology which can solve this problem easily
- 32:53where we have where we require to put in less effort.
- 32:58As I was telling you about when we introduced streaming
- 33:01processing, stream processing at the left earlier, it was based
- 33:05on the Cron job. So Cron job may have solved the
- 33:07problem when we were at small scale and it was OK.
- 33:11But as we started growing scaling system then we realized
- 33:16this is not able to scale and we need to look for the other
- 33:20technology. So streaming was one good use
- 33:23case where you don't need to write that much of code, you
- 33:27need to write less code and it's still able to process the data
- 33:31in real time. So that is 1.
- 33:33The other and which is other problem which is also relevant
- 33:36to this one is like how much effort that we need to put in to
- 33:40build this technology or use this technology.
- 33:43And that is most important one, as we try to move fast, it is
- 33:49very important that the operational cost or development
- 33:52cost is low on our side. So that way we can ship things
- 33:56faster. The other part is the cost as
- 34:00well. Over time we have you know move
- 34:04from one solution to other mainly because initially when we
- 34:08launched services it worked fine, but cost wise it was fine.
- 34:13But as we are scaling up, we realize that certain places we
- 34:16are like you know spending more, we could cut down those things.
- 34:20Then we realize there OK, maybe there is other alternative or
- 34:24maybe there is other way of like doing things and when we look
- 34:27into it and we realize yes, there so cost is the other one
- 34:31as well. We tried to look for what we
- 34:34call technology which could be cheaper for us.
- 34:38So that is the other one, the open source versus so open
- 34:43source as well, if anything is open source, well adopted by the
- 34:47community or well supported by the community, that is another
- 34:50consideration. One more is the art ecosystem,
- 34:55how well that technology or framework can integrate well
- 35:00with our ecosystem. If it is really hard to
- 35:04integrate it, then it may not be a kind of a good sell for us.
- 35:08Example could be the stream processing.
- 35:10We could have chosen Flink, you know, directly.
- 35:14Yeah. But we did not use it mainly
- 35:17because if we move from Python to Java, it would have been a
- 35:21kind of very huge investment for us.
- 35:25And and at that time, like we were scaling and we were also
- 35:29trying new technology. You do not want to take too many
- 35:32problems and try to solve them like you probably solve 1.
- 35:36And that's why we said like, OK, we can choose a technology which
- 35:40could be a good fit. And Python, most of the people
- 35:43were familiar with the Python, so we chose a Batcha Beam
- 35:47because a Batcha Beam supports a Python SDK as well.
- 35:50So, yeah, these are the some of the considerations that we put
- 35:55in before finalizing any technology or framework.
- 36:00Can you imagine trying to sell a data scientist on using Java?
- 36:05No, they will not like it it. Will not work at all.
- 36:10Yeah, Python is well supported and I I think our customers are
- 36:14data science and ML engineer. We do not want to introduce any
- 36:19kind of solution, right, which will create unnecessary
- 36:22friction. We want to create tools which
- 36:26will make their life easier, right?
- 36:29So and yeah, if it does not fit well in our ecosystem, even the
- 36:34tool is great, it may not work well.
- 36:39So and if there is any kind of bridge, there is a solution
- 36:42which can bridge the gap, that would be great.
- 36:45So we can probably consider both.
- 36:46Then whatever the solution which can bridge the bridge the gap
- 36:50and the final solution. Then it makes sense too that you
- 36:55look at that bridge as how much developer time, how difficult is
- 37:03this going to be to integrate into our system?
- 37:08How often are you trying to look at what's on the market to see
- 37:15if you can cut costs? Is this like a quarterly thing?
- 37:21Is it a weekly thing? Is it a monthly or yearly thing?
- 37:25I would say it depends on case by case.
- 37:27I don't think we look at every day, but we do have monitoring
- 37:33in place. If let's say if there's a
- 37:37significant increase in cost, we know that why it has increased
- 37:41and then probably if it has crossed certain thresholds, then
- 37:45we will look into it like why they and if there is anything we
- 37:49can do to bring down cost like without changing the technology
- 37:55or framework, we would do it. Like if, if there is a kind of a
- 37:57roadblock which is preventing us not or which does not allow us
- 38:03to reduce the cost, then we have to think about, Roger, maybe we
- 38:07should look for the other technology.
- 38:09But it completely depends on the scenarios like how much you are
- 38:12spending, what is the budget and what is our capacity to move to
- 38:17a new technology. Yeah, We had bro hit on here
- 38:21probably 3-4 weeks ago and he talked about how a huge boon has
- 38:30been for folks that he works with recognizing if they don't
- 38:36actually need the freshness of data that they think they need.
- 38:40So just being able to checkpoint right data from going from one
- 38:45second to 10 second checkpoints, he was like, you can save a lot
- 38:49of money with that. Oh yeah, yeah.
- 38:52So there's another process that we have is onboarding.
- 38:57So whenever someone comes and say, you know, we want to build
- 39:00a real time feature and like, and then our question is like,
- 39:02do you really need a real time feature or do you need offline
- 39:05feature? And we ask all those questions
- 39:08based on their use cases, try to determine if they really need
- 39:11it. If they do not need it, then we
- 39:14point them to the offline data stores.
- 39:16You can build there, you can add, because if you're moving
- 39:20towards real time, it requires more effort, more money to have
- 39:26that solution. If you do not need it, then you
- 39:29are unnecessarily spending that much of time and effort to have
- 39:33it. And that's why we said like we
- 39:36vet all these requests and if they are genuinely or genuinely
- 39:42needed. If that you know if it is it is
- 39:45must to have it, then only we do it, otherwise we provide other
- 39:50solutions, other offline solutions.
- 39:52But why do you think that people are convinced they need some
- 39:57type of real time feature? Why they're convinced that they
- 40:02needed. So yeah, why did?
- 40:03Why do they come to you thinking that they need real time?
- 40:06Sometime, you know, they do not know that how much effort is
- 40:13required, how much money we spend on, you know, generating
- 40:17all these real time feature. You abstract all that away so
- 40:20they think, oh just throw another real time feature in
- 40:23the. So they feel it's, it is cheap
- 40:26and and that's why they think that, OK, we can just have it
- 40:29anyway it is available. So I don't we just use it right.
- 40:33But as we own the platform, we generate all this, we know how
- 40:37much effort and effort, time as well as money that we need to,
- 40:42you know, spend on this. And we are really conscious like
- 40:46when we made that decision. And so the data scientist get to
- 40:50experiment with the offline stuff and say I'm a data
- 40:55scientist and I discover that there's this feature that is
- 41:01when someone logs on to lift, they search their ride, but they
- 41:07don't actually get the ride and they log off of it.
- 41:11We predict that X amount of X percent of times they're going
- 41:18to come back and order that ride.
- 41:20So I want that feature in my model something.
- 41:25I know I'm oversimplifying the shit out of it, but just go with
- 41:28me here on this. I want that feature on my model.
- 41:31I see that offline. It actually gives my model some
- 41:35help. Then I go to you and I say, hey,
- 41:41I need this feature in my model. You come and you try and
- 41:45convince me that I don't actually need it.
- 41:47Isn't the model you say, Are you sure about that?
- 41:50Can we maybe do something else? Is there potential for us to
- 41:53just do this batch and eventually we settle on yes, I
- 41:59need it. Then I go to saying, well, what
- 42:03type of detail I want or I guess that would have already been
- 42:06solved back in the beginning when I say what geohash do I
- 42:10need? Yeah.
- 42:11So like if I'm convinced that OK, this is a real time use case
- 42:16and we are going to work on this one, then we will can.
- 42:18And this is very super specialized use case where we
- 42:22need more support to build it, then our ingenious will
- 42:25transform that query into a pipeline.
- 42:29And since these ingenious know how to build a pipeline which,
- 42:33which is scalable, they will transform the whole processing.
- 42:37So at the high level you will get the same data.
- 42:40It's just that the processing could be slightly different.
- 42:43And I, I think one of the optimization techniques that we
- 42:46use and I have written in blog about it as well, we try to drop
- 42:53unnecessary data early on in the pipeline.
- 42:57And we trying to let's say like you are getting tons of data,
- 43:01they may not be relevant to you. All right.
- 43:04So as soon as we find this information, we drop it then
- 43:08like we do not let the data pass to the entire pipeline.
- 43:12And we have done that experiment like like early dropping versus
- 43:17late dropping and we had seen at least 20% increase in efficiency
- 43:23and even the latency improved. And that's when we made the
- 43:26decision not like we will try to figure out all these data early
- 43:31on and if they are not relevant, drop it and then process it.
- 43:35And the the next step is also sometime the if you look at the
- 43:40offline queries, they do mega joins each other like you know
- 43:46tons of joins and all those things.
- 43:48The real time processing does not work in that way.
- 43:51You can do it, but it will very costly and unscalable.
- 43:55What we do is even joins, we try to divide into a different
- 43:59dimensions. So the high level idea is that
- 44:02you divide the data into smaller groups and you perform the
- 44:07operation. Smaller data is very manageable
- 44:11than the bigger data. Yeah.
- 44:12So it's more like a divide and conquer.
- 44:14You are dividing bigger data set into smaller, process them and
- 44:18then process it further. So that way you can manage it.
- 44:23Otherwise it's really hard. If you had to guess, how many
- 44:27pipelines are you up keeping right now?
- 44:33Are we talking thousands, 10s of thousands, or hundreds?
- 44:38So and definitely not 10s of thousands, we are really
- 44:41conscious about it how we are building the pipeline.
- 44:44There are two ways we can do it. 1 is like where people can build
- 44:48a pipeline by themselves. The other one is super sliced
- 44:50feature so super specialized like I would say 30 close 30-40
- 44:56pipelines and these pipeline not necessarily generating only 40
- 45:00feature like 1 pipeline itself can generate 10's and fifteenths
- 45:05of feature. And when I say feature, it is
- 45:07basically for one region and but they will be processing almost
- 45:12millions of data per minute or so.
- 45:14Wow. Yeah.
- 45:16So that's how they're, I do not have the full account of like
- 45:20how many pipelines that we currently run, but it definitely
- 45:24somewhere in hundreds. Something that you mentioned
- 45:27here is that there's self-serve in a way.
- 45:31How does that work? Are the data scientists going
- 45:33and they're trying to stand up MVP and then you come in a few
- 45:38days later or however many weeks later and you make it
- 45:42bulletproof? Yeah.
- 45:44So I can sell services. Those are very simple use cases
- 45:48like where you know processing only for smaller scale.
- 45:51Like maybe you're processing individual user, you're not
- 45:54doing a heavy processing of the data.
- 45:57And those operations are really, really straightforward.
- 46:00You know, like you're getting a user data and you're extracting
- 46:04out what is the right request at time and then the storing
- 46:08somewhere. Those could be the simple one
- 46:10and since they are really easy, you don't need huge
- 46:15understanding of how streaming processing works.
- 46:17So they can just do it by themselves without much help.
- 46:20And anyway, we have simplified the St.
- 46:22KS and the whole infrastructure so they can bring up the whole
- 46:26like the pipeline by themselves. So that is 1.
- 46:29The other one is where it is super specialized, where it
- 46:32requires very heavy lifting or heavy processing.
- 46:35That's when some of the specialized team, they come in
- 46:39and help help the data science person or ML engineer.
- 46:44No. I know that people talk a bunch
- 46:47about like the data getting skewed in offline, online type
- 46:53of scenarios. What are you doing to mitigate
- 46:59that? How do you go about that?
- 47:00Is that in something that you had already talked about?
- 47:03I think I did talk about that one as well.
- 47:06And data skewness or heart Shard.
- 47:09These are like interleaved things and whenever either you
- 47:14are in offline online, I think online world is more affected by
- 47:19that one. And we are like early on when we
- 47:23were thinking that that will not affect us and we build the
- 47:28pipeline and it was not super performant.
- 47:31Like there were some of the nodes which we are getting way
- 47:34more data and they had to do way more processing and the latency
- 47:39was huge. One bad thing about stream
- 47:45processing is that if anyone node is slow it will slow down
- 47:50the entire processing as well. It it creates A barrier like if
- 47:54one node has not processed it then the whole thing does not
- 47:59move forward. It waits for that node to
- 48:02process then the other node will also move forward.
- 48:06So, so that is that was a problem.
- 48:09And I, I think the data skewness, if you have to look at
- 48:12the data like how the data is distributed and if you have a
- 48:17good understanding about that one, then you have to come back
- 48:19to the to the pipeline design and figure out how you can
- 48:23further redistribute the data to avoid the data skewness.
- 48:28In our case, region causes a huge data skewness.
- 48:33It is like 8080% by 20% rule that means 20% of the cities,
- 48:40they are generating almost 80% of data.
- 48:42And so for those big cities we have to really cautious about
- 48:46it. And in our case we just use the
- 48:49geohash to further redistribute the data.
- 48:53So from like you know, 300 plus cities to almost millions of
- 49:00geohashes. So that way you are able to
- 49:02redistribute the data and like you can avoid the data skewness
- 49:07as well. I didn't realize that that was
- 49:12the same thing. You were calling it hot Shard.
- 49:16Yeah. Which I like that word now that
- 49:18you're saying it. So data is, this is like there's
- 49:22this concentration of data on one particular node or
- 49:25something. And the problem what happens is
- 49:28that like if there's a huge concentration on one node, then
- 49:32that node is called heart, heart node, heart Shard because that
- 49:37is the one which is processing most of it, but they are
- 49:39deleted. Yeah, 'cause I guess I was
- 49:43confusing it for the training serving SKU that you get with
- 49:48the the the data sometimes and how you can mitigate that.
- 49:54But it makes a lot of sense, this hot Shard and the data
- 49:58skewedness, seeing the saturation on certain nodes
- 50:03because there's so much more traffic on these different hot
- 50:07cities. But then if you break it down to
- 50:11smaller bits and you have these packages where you're just
- 50:15looking at blocks a square block radius, then it's it's a
- 50:20different problem that you're dealing with.
- 50:22Exactly. And you you just redistributing
- 50:24the whole data to all different nodes.
- 50:27Yeah, it's a nice trick. I like that.
- 50:30What other tricks do you got for me?
- 50:32What else have you learned over the years?
- 50:35Yeah. So I, I earlier mentioned that
- 50:37we divided into two or three different phases.
- 50:39So very first phase POC, we scale, we tried to scale, we ran
- 50:43into some of the roadblocks, a heart shark one, one of them.
- 50:47We addressed that and then we started creating multiple
- 50:50pipelines. Then we realized that, you know,
- 50:54it is kind of easy for to build a pipeline, but as you're
- 51:00increasing number of pipelines, right, you're also increasing
- 51:03the cost. And we closely look into all the
- 51:06pipelines and we realize most of the pipelines are doing almost
- 51:11very similar processing at the beginning of the pipeline or
- 51:15there are a couple of operators which are doing something
- 51:18similar. We thought like it can be
- 51:21abstracted out and and centralized into one place.
- 51:26So that way you do that processing only once and that
- 51:30can allow you to save the cost. So what we did is we defined 2
- 51:35stage pipeline. One stage is for preprocessing
- 51:38all these data. So all these data filtering and
- 51:42building a kind of state for the user.
- 51:45So earlier each pipeline was generating one feature and and
- 51:50if you have to generate another feature, you have to build
- 51:52another one. What we said like we sent like
- 51:54we said like we just combine all of them into one.
- 51:58So now we have 1 pipeline which process the data and it drops
- 52:03unnecessary data. It also builds the kind of state
- 52:07of the user like whether that user has book a ride, whether he
- 52:13got it right or not, whether he dropped off.
- 52:15So we have maintained the state of the user similarly for both
- 52:20like passenger and driver and based on that we know the
- 52:26current state of the world and we have all these metadata
- 52:32stored and immediate every minute or so.
- 52:36So the downstream processing that is basically aggregating
- 52:39all these data, they can get all the relevant information and
- 52:43then they can aggregate it. And so the aggregation logic is
- 52:48different for different features.
- 52:49So you can have a different pipelines.
- 52:52Does it make sense or? So what I was saying is like,
- 52:55whatever the common processing, we extracted out and we
- 52:58centralized it. Yeah, but we separated out other
- 53:02pipe pipelines where their processing logic was different.
- 53:07And that's how we were able to cut, cut cost and centralized
- 53:09the processing. The other thing that we did is
- 53:12like writing code was kind of used to take longer time.
- 53:17What we did is like we came up with the YAML based pipeline
- 53:21generation where you do not need to write code.
- 53:24You write a kind of YAML configuration file and it does
- 53:28the processing for you. So that cut down the development
- 53:32time as well. Tell me more about.
- 53:35That So what we did is like we realized that you know if we
- 53:41have to build a new feature most of the time we are doing very
- 53:46similar processing so let's say if you want to figure out
- 53:51whether this is a driver or passenger, that is 1 function
- 53:57right left. So what we did is like we find
- 53:59all these common functionality, we provide that SDK and then.
- 54:04Yeah, OK, I get it. You would put it into the YAML
- 54:09as something that people could just use.
- 54:11They can define it's already defined and then wow, OK.
- 54:17So we said like, OK, you know, I do not want our data scientist
- 54:22to understand the whole thing, like how to write a pipeline.
- 54:26I'll say that, OK, I'll define a very simple way of defining A
- 54:29pipeline. So I will create all these, you
- 54:33know, general purpose functionality for you and then
- 54:36you can just declare this in a YAML file how you want to
- 54:41process. So they do not need to
- 54:43understand how to define the windowing, how we're doing work
- 54:48and all. They just need to tell like I
- 54:50need this one minute long window or two-minute long or whatever.
- 54:53And then just define that in a YAML and our system will read
- 54:59that YAML file. Look at like how you are defined
- 55:02all pipeline and will build the pipeline for you.
- 55:05Yeah, that cut down our development time.
- 55:09No. You did mention that certain
- 55:11pipelines have 5 different features being created with
- 55:16them. You're getting like 2 for the
- 55:18price of one on certain pipelines, right?
- 55:21Is it that they have certain steps that they're doing
- 55:27together? Like, there's these certain
- 55:28functions and so you can bundle them up, but eventually they
- 55:34diverge, yes. That's right.
- 55:37Like you, So the common functionalities they are a kind
- 55:41of margin and centralized, the specialized zone still brashed
- 55:45out and that's how like we are able to save it earlier like all
- 55:49these pipeline was kind of independent but you know we were
- 55:52wasting other sources with yeah, OK, let's combine the
- 55:55centralized pieces. Dude, this has been awesome.
- 55:58Is there anything else that you want to hit on that we didn't
- 56:01talk about? I think we have current most of
- 56:04it. But yeah, I would like if you
- 56:06have any other question, just let me know.
- 56:08I'm just so glad you didn't say, oh, we found a way to cut down
- 56:12on our coding time. I thought for sure you were
- 56:14going to say, we now use cursor and AI code generation.
- 56:18And I was putting, I was like, please don't say that.
- 56:21It's some of them are like precursor as well.
- 56:25So when we initially introduced the pipeline, right, we were
- 56:29able to cut down almost like 60% of the code base.
- 56:33Wow, because of the streaming like streaming provide all
- 56:36these, you know, processing what we call operators or what we
- 56:41call functionality where you do not need to write those code
- 56:44like let's say if you want to join anything, you can just
- 56:47write one operator. It does that work for you.
- 56:49Like it hides all the what we call implementation details from
- 56:53you. So if it's pretty simple then
- 56:56what we did is like we further went ahead and said, OK, even I
- 56:59do not want to define all these operator like what is the
- 57:02easiest way to do it? And we came up with a
- 57:04declarative YAML based pipeline, so where you just need to write
- 57:07one line or like for one operator you just need to
- 57:11declare A1 line configuration. That's all.
- 57:14That's so smart. That pipeline is not more than
- 57:18or like that definition is not more than 2030 lines of code
- 57:23rest of the other rest of the other like processing that is
- 57:27like hidden by our platform. It is completely abstracted out
- 57:31so they do not need to worry about it.
- 57:33So now you can think about where we had thousands and thousands
- 57:36of line of code for processing one feature, then we cut it down
- 57:40to almost 30 or 40 lines of YAML based configuration.
- 57:46That's why you get paid big bucks.
- 57:48I'll tell you what, that is a genius implementation.
- 57:51I like it.