Latest / Talk Python To Me / #324: Gatorade-powered Python APIs
Transcript
- 0:00Python is used to solve a large and varied set of problems.
- 0:03One of its core pillars is web APIs.
- 0:05Another one is ML and data science.
- 0:08Those two important pieces were brought together in an unexpected and yet magically futuristic
- 0:13way by Rod Senra's team working with the Gatorade Sports Science Institute.
- 0:18They created a patch that you wear while working out once or twice.
- 0:22It analyzes your perspiration, combines it with other factors like running distance, sleep
- 0:27quality, and more.
- 0:28Then it provides recommendations using Python about how to get more effective fitness.
- 0:33This is Talk Python To Me, episode 324, recorded July 8th, 2021.
- 0:38Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 0:56ecosystem, and the personalities.
- 0:58This is your host, Michael Kennedy.
- 0:59Follow me on Twitter where I'm @mkennedy.
- 1:02And keep up with the show and listen to past episodes at talkpython.fm.
- 1:05And follow the show on Twitter via at Talk Python.
- 1:08This episode is brought to you by Sentry and Linode.
- 1:12And the transcripts are brought to you by Assembly AI.
- 1:15Please check out what they're offering during their segments.
- 1:17It really helps support the show.
- 1:19Rod, welcome to Talk Python To Me.
- 1:21Thank you.
- 1:22Super to have you here.
- 1:23There's a lot of things you've been building for different companies through your work.
- 1:28That's going to be really fun to explore.
- 1:30I think one of the really neat things here is you're not just working for one company, working
- 1:35on one team the way it works, but you're kind of interacting with a bunch of different projects
- 1:40and types of technologies.
- 1:41So you'll have a good, broad perspective on what went well, what didn't, what you would
- 1:45change, and so on.
- 1:46That's true.
- 1:47Python is the one thing that stuck with me since 1997 across different companies, let's
- 1:52say like five different companies, two different continents.
- 1:56But Python was the one thing that remained the same.
- 1:59That's fantastic.
- 2:01A good choice indeed.
- 2:02Well, let's start this conversation by talking about your story and how you got into programming
- 2:09Python.
- 2:09Python, it sounds like you were one of the early adopters.
- 2:12What version of Python?
- 2:13That was probably a version one type of thing.
- 2:15It was 1.5.2.
- 2:17It was in 1997.
- 2:19At that time, I was almost finishing my undergraduate course in computer engineering, and I already
- 2:27engaged in my master's post-graduation course.
- 2:30What were you studying?
- 2:31What was your degree?
- 2:32Well, my undergraduate degree was computer engineering.
- 2:35But for the master's thesis, I was studying computational reflection.
- 2:39In the end, it's the line of research that led to Aspect J and other things.
- 2:45But it was all about object-oriented protocols.
- 2:48So how you organize object orientation in programming languages, those kind of things.
- 2:53Okay.
- 2:53Cool.
- 2:53And Aspect J, that's like aspect-oriented programming?
- 2:57Exactly.
- 2:57Aspect-oriented programming was like a byproduct of the research in computational reflection.
- 3:03At the time, we were, academically speaking, we were trying to figure out what can you do
- 3:09with reflection.
- 3:11Java was one of the languages that made it popular to do introspection and reflection
- 3:17in programming languages.
- 3:18Of course, we had that in Lisp since back to the 70s.
- 3:22But Java made it known to the wide world world.
- 3:26So then we became researching more formally.
- 3:29And I started probing supports for reflective programming in programming languages.
- 3:36And that meant not only Java, but at the time, Perl, Python, Tcl.
- 3:40And once I saw Python, it felt like a glove to my hands.
- 3:45And then I stuck with it.
- 3:47Yeah.
- 3:47Oh, that's really neat.
- 3:48Maybe you could just talk a little tiny bit about what reflection is for people listening
- 3:53who maybe haven't done a lot of Java or .NET.
- 3:57They have it as well.
- 3:58And in Python, we have it in the sense that you can go in and explore the types.
- 4:03And so, you know, give it an object.
- 4:05What if it's class?
- 4:06And like, what is it?
- 4:07It's meta class.
- 4:07And you can like dig into it and even change it.
- 4:09But I don't typically hear it referred to as reflection in the Python ecosystem.
- 4:14Right.
- 4:15Yeah.
- 4:15Introspection became a more common term used.
- 4:19But at the time, reflection was about creating programs that reason about programs.
- 4:26So it was about this meta level reasoning.
- 4:29And it was very popular to do non-functional aspects.
- 4:32So you want to write your code and the code has the functional aspects, what it do, how it
- 4:39like transform things.
- 4:40And then the non-functional aspects like logging, persistency, monitoring, those kinds of things.
- 4:47People were exploring how to detach, decouple those things from your actual program and do
- 4:53that on a separate layer.
- 4:55And that was what reflection was all about.
- 4:57It was about having as inputs your own code and as outputs changing the behavior of your program.
- 5:05And the way we attacked that at the time was by an interception mechanism.
- 5:11So Python always had that.
- 5:13I think they called the DOM buildry hook or something like that, where you could like intercept
- 5:19like anything that was happening there.
- 5:21We do have the bugging hook in the Sys module that allow us to like pause your computation and
- 5:29see what's happening.
- 5:30Other programming languages.
- 5:32And at the time we're talking about the 90s, the popular ones were statically compiled
- 5:38programming languages.
- 5:39Right.
- 5:39C, C++, they generally don't have this behavior.
- 5:42Yeah.
- 5:42Sometimes they had runtime type information when you compiled your source codes enabling that.
- 5:48That's right.
- 5:48I remember there was an RTTI.
- 5:50RTTI.
- 5:51And C++, but it was off by default.
- 5:54Exactly.
- 5:55But in the interpreted world, you had everything, right?
- 5:58You had the interpreter during runtime.
- 6:01Sometimes you had the compiler as well, which was true for Java, which was true for Python,
- 6:07Perl, all the interpreted dynamically languages.
- 6:11And then that became more of a thing.
- 6:13Of course, in time, people realized there were other ways to achieve the same goals, which
- 6:20were more effective because one of the main things with introspection and interception
- 6:26is that everything that is happening in your program, it's kind of being reified, delivered
- 6:33to this meta level and then handled as data.
- 6:36So that is like a major break in speed, right?
- 6:42So it was not the answer for everything, especially when you wanted to have like runtime performance.
- 6:49But for things that were offline batch or analysis, it was not a problem.
- 6:53And one thing that an exercise that I'd done at the time, which is kind of interesting, was
- 6:59to introduce a debugger during runtime.
- 7:02So because we had this reflection mechanism that works just like this, you could take possession
- 7:09of an object and then any interaction with these objects would go to its guardian angel,
- 7:15which I call the meta object of this object.
- 7:18And then the meta object decided what to do.
- 7:20To lie about what was happening, to just delegate back to that object down there, do something else,
- 7:28become a proxy, solve the computation.
- 7:30So you could do anything.
- 7:32And in that case, we could install a debugger just for a given class or a given instance of your program,
- 7:40and then propagate like a virus for anything either that class or instance touched.
- 7:45So that was kind of interesting, a new dimension of programming, but became more as an academic exercise.
- 7:51And the only thing that I remember that's kind of succeeded into the industry was aspect oriented programming of sorts.
- 8:00Well, that's very interesting.
- 8:01It seems to me a little bit like decorators.
- 8:04Yes.
- 8:05Decorators are wrappers.
- 8:06But the thing is, they are not transparent.
- 8:10So whenever you create a decorator or a proxy, what's happening is that the references you had to the original objects now need to point to the wrapper, to the decorator.
- 8:21Right?
- 8:22So the key insights for reflectional computation that we were exploring at the time was how do we make this proxy totally transparent?
- 8:31So if you have a pointer or a reference to an object before it became reflective, it would still be valid.
- 8:41So you can turn on and off those introspection mechanisms and interception mechanism, and it's totally transparent.
- 8:48So to achieve that, we had to change the interpreter.
- 8:52So that's how we've done it for Java.
- 8:54And that's how I was exploring at the time for Python itself and Perl, to change the interpreter, to add the hook in there and do transparent wrapping.
- 9:04Yeah.
- 9:04It seems like some of the new peps might make it possible to plug in now rather than actually change it.
- 9:10I know there's that JIT plugin that they're working in where you can intercept the method parsing compilation bits and stuff.
- 9:17I don't remember the number.
- 9:18Yeah.
- 9:18I haven't explored, like, doing it to modern Python.
- 9:21At the time, I did some exercises using the debug hook.
- 9:26Yeah.
- 9:26It kind of works, but it was kind of messy and super slow.
- 9:29So I kind of stopped.
- 9:31But it will be interesting to revisit that again.
- 9:34I'm sure.
- 9:35I do remember how interesting all the research was around that time.
- 9:39And I feel like a lot of what's happening now is it's getting a little more structured, a little less dynamic with things like decorators and other types of wrappers and inner functions and stuff.
- 9:49But yeah, quite an interesting time.
- 9:50So how about now?
- 9:52Maybe we can talk about what you're doing these days.
- 9:54Nowadays, I'm a technology director at Working Co.
- 9:57Working Co.
- 9:58Working Co.
- 9:58is a digital products company where we not only do designs and strategy, but we also do implementation and quality assurance for the projects that we take on.
- 10:11So that's what makes us different from just an agency, a design agency, because the founders of Working Co.
- 10:17realize that it's much better for the clients to hire a single entity to do the full digital products turnkey.
- 10:26And then we can make sure that whatever we design, it's possible to build.
- 10:30So that is the vision for Working Co.
- 10:32We were very successful, I must say.
- 10:35In a few years, Working Co. won many prizes.
- 10:38It became famous for the Virgin America app for booking passages with Virgin America, I guess, five or six years ago.
- 10:47But we're doing things for like Apple, Google, Chase, you name it.
- 10:52I know that involves a lot of Python.
- 10:53Does it involve other technologies?
- 10:55It's worth it.
- 10:56Probably other technologies as well, right?
- 10:58Somebody comes and says, well, we want this thing designed and four of our Java shops don't make it for Java.
- 11:02Whatever happens is usually there are projects that are just designed, projects that are designed plus front-end work.
- 11:08Like projects that go all the way through to back-end.
- 11:11Sometimes back-end is just like a mediator for some infrastructure that the clients already have.
- 11:17But there are other times where we have to do everything, like the full digital platform for the client.
- 11:24And in those cases, Python becomes a key technology for us.
- 11:29Because what Python gives you most, in my experience, is optimizing for development time, right?
- 11:36People are very much concerned about Python runtime efficiency.
- 11:40But the key problem is development efficiency, right?
- 11:45Most of the time, if it's a little bit slower, like in comparison, a Formula One car and a regular vehicle, one is much faster than the other.
- 11:56We don't need Formula One cars most of the time, right?
- 12:00That's right.
- 12:00So it's like fast enough.
- 12:01And that is the point.
- 12:03So for many things, Python is fast enough.
- 12:06But in terms of development time, Python is the Formula One vehicle.
- 12:10It's like super fast.
- 12:12It's super easy to throw things away.
- 12:14It's super easy to explore.
- 12:15It can touch every niche in computer size.
- 12:18And I kind of have...
- 12:20Yeah, exactly.
- 12:21It has PyPI, right?
- 12:23For example, you can install this and go.
- 12:25Exactly.
- 12:26So it was a key technology for us in those cases that we have an extremely agile cycle of development.
- 12:32Lots of changes because design was sometimes moving along the way.
- 12:36And we need to rebuild the backend infrastructure overnight.
- 12:39So because for those scenarios, it was key.
- 12:43I think the conversation around performance in Python is super interesting because there's just so many layers and variations.
- 12:50Yeah.
- 12:51And what are you trying to do?
- 12:53Well, if you're trying to do a tight loop that does math, guess what?
- 12:56Python's bad at that.
- 12:57But maybe you shouldn't be doing that.
- 12:58Maybe you should be using NumPy and the SciPy stuff.
- 13:01And then all of a sudden, it's C speed again.
- 13:02Yes.
- 13:03Maybe you're doing some data-driven web API.
- 13:07And it's like, well, it might be slow.
- 13:09Well, actually, what you're doing is you're orchestrating exchange of JSON and talking to a database server or cluster.
- 13:15And it's almost exactly the same speed as if it were written in C because you're mostly waiting on the database and waiting on the network.
- 13:21And there's all of those things.
- 13:23And then on top of it is this thing that you talk about that often gets ignored.
- 13:27There's a really interesting story that was recounted in Mike Driscoll's Python interviews book about the competition between Google Video and YouTube and how Google Video had like 100 C++ engineers.
- 13:40And YouTube, this little startup, had 20 Python developers.
- 13:45And YouTube was just blowing away all the Google engineers because they could add features faster.
- 13:50And if Google would do something, they could copy it, re-implement it really quickly.
- 13:53And so Google fixed the problem by buying YouTube.
- 13:56It's still Python to some degree there.
- 13:59So that's a really good point.
- 14:01Yeah.
- 14:01My experience, there are two factors.
- 14:04One factor that you just mentioned is having it under control when it grows.
- 14:09Right?
- 14:09So software is like a living thing.
- 14:12You start a project.
- 14:13It gets, it's born.
- 14:14It starts to grow.
- 14:16Right.
- 14:16Does it become a sequoia or does it become blackberry bushes?
- 14:19Exactly.
- 14:20This portion of Talk Python, I mean, is brought to you by Sentry.
- 14:25How would you like to remove a little stress from your life?
- 14:27Do you worry that users might be having difficulties or are encountering errors in your app right now?
- 14:32Do you even know it until they send that support email?
- 14:35How much better would it be to have the error and performance details immediately sent to you,
- 14:41including the call stack and values of local variables and the active user recorded in that report?
- 14:47With Sentry, this is not only possible, it's simple.
- 14:50In fact, we use Sentry on all the Talk Python web properties.
- 14:53We've actually fixed a bug triggered by a user and had the upgrade ready to roll out as we got their support email.
- 15:00That was a great email to write back.
- 15:02We saw your error and have already rolled out the fix.
- 15:04Imagine their surprise.
- 15:05Surprise and delight your users today.
- 15:08Create your Sentry account at talkpython.fm/sentry.
- 15:11And if you sign up with the code talkpython2021, it's good for two months of Sentry's team plan,
- 15:17which will give you up to 20 times as many monthly events as well as other features.
- 15:22So just use that code talkpython2021 as your promo code when you sign up.
- 15:29So it has this life cycle, right?
- 15:31At some point, depending on its history, it gets out of control.
- 15:36So if you didn't have the proper team, the proper guidance, it can become the problem.
- 15:43Not the problem it was supposed to solve, but the software itself becomes a problem.
- 15:48And then people tend to, oh, let's throw this away and get something else because this is unmanageable.
- 15:53And I don't think it's an intrinsic problem on any programming language or infrastructure.
- 15:58It's more between the matching of did the team that was doing this really master the technology at the time.
- 16:08If they do, it could be Fortran, COBOL, C++, or Python.
- 16:12You have good results.
- 16:14If they didn't, they might get into this one-side, one-way road in the opposite direction.
- 16:20Then they are screwed, right?
- 16:22So this is one thing.
- 16:24The other thing, it's all about flexibility and the performance that you mentioned.
- 16:28For example, in this latest project that we are tackling, the GX project, we have it all.
- 16:33We had CPU-bound problems that we are tackling, IO-bound problems.
- 16:38And in both cases, Python was behaving just fine.
- 16:41We have like 16,000 users right now.
- 16:45We have three API instances.
- 16:47And when it's a performance problem, we change the algorithm, we introduce caching, we're using MongoDB for scalability, and we have zero performance issues so far.
- 16:58But because we have the software under control, we know what's happening in there.
- 17:04Technology is not a mystery.
- 17:05Then it's easy to pinpoint what's wrong and then replace it for a new version fast.
- 17:12And that's it.
- 17:13It's bringing results.
- 17:14That's a fantastic point.
- 17:15You know, you've got the architectural considerations as well as just the raw technology, right?
- 17:20Oh yeah, for sure.
- 17:21It's a single thing.
- 17:22That's why I use the metaphor of like a living organism, because it's on an ecosystem.
- 17:27Your software is not an island anymore.
- 17:30In the past, we had like this release to the desktop, install, and it's all on your machine.
- 17:37But today, it's interacting with the operating system, with the cloud, with the user.
- 17:43So it's alive, right?
- 17:45It's a dynamic ecosystem.
- 17:46So it's all about those interactions and understanding the dynamics on each of these interfaces, and then optimizing for the Feng Shui, for the flow.
- 17:56Very cool.
- 17:57And I want to dive into this first API, because I think it's super interesting, and people are going to be really surprised by it, I'm sure.
- 18:04Oh, that's good.
- 18:04Yeah, it'll be fun.
- 18:05But before I do, I do want to ask you one more sort of big picture question.
- 18:09You're working with Work & Co., you're working with all these clients as this digital agency doing this end-to-end work, which I think makes a lot of sense.
- 18:17What is the trends for Python that you've seen across the last five years or so?
- 18:24I see.
- 18:24What has stood out to you from these conversations?
- 18:27Maybe you had five, ten years ago, you're having now, you're thinking about the future.
- 18:30The two things that are my reality, at least, and that doesn't mean like, it's a broad world that we have out there.
- 18:37So there are many cases, right?
- 18:39So I'll speak just from my experience in the last three years.
- 18:42So there are two things that come to mind.
- 18:45One of them is this mediator thing.
- 18:49So because everything is in the cloud, because you're not writing any more software from scratch,
- 18:55you have to do integration, like gluing.
- 18:58Python, back in the early days, became famous as a glue language.
- 19:03And it was kind of gluing things in the desktop.
- 19:05Now Python is gluing things in the cloud.
- 19:09Because Python is such a versatile language in terms of a huge ecosystem of libraries,
- 19:15because the language itself allows you to compute like anything,
- 19:19it became an excellent technology for a glue language.
- 19:22And for us, it's critical, because any project we're dealing with, okay, we have to talk to a database, for sure,
- 19:31but we also have to talk to a forecasting weather service.
- 19:35We have to talk to a push notification service.
- 19:38We have to talk to analytics system platform.
- 19:42So you need to send signals there.
- 19:44So this ecosystem thing is great for that, because you find the connectors, you find the drivers, you find examples.
- 19:53So all of that speeds up the cycle of development and gives you confidence that you achieve whatever you need in success.
- 20:01In terms of ecosystems, still, we're not talking about just the computer right now.
- 20:06So we did a project for Google, the new store in Google.
- 20:09There are some embedded devices there.
- 20:12So that's another niche, embedded systems, IoT, things for the television.
- 20:18We did things for Marriott, where it was like embedded on a setup box.
- 20:22So this is one thing that I think we're going to see more and more often.
- 20:25Now that we see like CPUs in your lamps, and people playing boom in their lamps.
- 20:30Right.
- 20:30The other thing, it's the data-driven aspect.
- 20:33So one of the flags that I carry at Working Co is the data-driven design.
- 20:38So data-driven design is like, okay, we are not doing design just based on the inspirational thing from designers and their creativity and their capacity for innovation, but anchor in data from the real world.
- 20:52Sometimes that approach goes all the way through conceptual design into the end product, which we are seeing with these machine learning, deep learning-based products.
- 21:05Email model in production behind Flask or something.
- 21:08Exactly.
- 21:09So that's another trend that Python is great, right?
- 21:15Not only for the business analytical aspects, but also for the pipelines to build models in production.
- 21:23Very neat.
- 21:23The way you described Python as a glue language is super interesting compared to the way it's traditionally been described.
- 21:31Traditionally, glue language meant something like, well, I've got a C library and I'm talking to Linux.
- 21:38And so I could write this stuff in Python that'll do some shell stuff with Linux and that it'll also like pull in the C API and just move that data from here to there and go.
- 21:48And it's come across a little bit as a second class thing.
- 21:52It's like the very best scripting language you can imagine.
- 21:55And it's kind of not perfect for apps, but well, we'll do this.
- 21:59But what you described was, we're going to take the database, we're going to take these APIs, we're going to take the web requests, we're going to glue that together.
- 22:07I mean, that is the application.
- 22:09And it's like, it's thinking, yeah, it's thinking of, well, really, what is a modern API app other than a thing that takes a little data from an inbound request,
- 22:20maybe pulls some, pushes something over to Celery, grab something out of the database, calls these APIs and bundles it back up as a response and sends it back with a status code.
- 22:29That's the entire application.
- 22:30And yet this idea of gluing these pieces together is a really interesting way to think of it.
- 22:35That's what I learned.
- 22:35It's about like gluing systems and gluing data.
- 22:39And of course, these things are connected, but sometimes you can have gluing data in a asynchronous way, right?
- 22:47In batch processing or local processing or for analysis or human interaction.
- 22:52But it's still like gluing data from several sources.
- 22:55And there's this other approach, which is like gluing live systems.
- 22:59And of course, data is flowing across them, but also the connectivity aspect is key, right?
- 23:05Can I authenticate and talk to all of these systems?
- 23:09In the way they expect to interchange information.
- 23:12The real power is how well does it perform that combination, not how well does that one millisecond versus two milliseconds in the actual WebView method runtime behave, right?
- 23:23Yes.
- 23:24It's super interesting to see it that way.
- 23:25All right, well, let's jump into the first API that we're going to talk about.
- 23:30Right.
- 23:30Yeah.
- 23:30So this has to do with Gatorade, which is the sports drink company.
- 23:35And they have created this really interesting idea of the quantified self for fitness here with this thing called the GX Sweat Patch.
- 23:46Exactly.
- 23:47This is something that blew my mind when I saw it first.
- 23:49Yes.
- 23:50This is something that is like really in the beginning.
- 23:52We launched this in production in March 1st this year.
- 23:56It has been in development since 2019.
- 23:59And the research inside Gatorade goes even far back.
- 24:03So what they are trying to do, Gatorade has this subunit called GSI, the Gatorade Sports Science Institute.
- 24:12I had the opportunity to visit one of their physical instances in Sarasota, Florida in 2020.
- 24:19And they do like amazing work there, like bridging sports science, like students, actual experiments.
- 24:27And they are helping to develop this concept of how do you bring some of the metrics used by high performance athletes to a more general, broad audience?
- 24:40Right.
- 24:40We've probably all seen pictures of Olympic athletes or, you know, pick your favorite sport athletes with a couple of doctors or researchers around with a clipboard and like a big breathing thing.
- 24:53And they're on like a workout bike or they're doing and they're like studying all these different things.
- 24:58Right.
- 24:58And they get really interesting feedback on, well, under this situation, this is where you're hitting your limits in cardio or in like breathing at altitude or something.
- 25:10And for the rest of us, we just put on shoes and run or, you know, get on a bike or whatever it is.
- 25:16And we just have no idea.
- 25:16In a specific case of the, what you're showing now on the screen, the sweat patch, this thing that you can put in your forearm and it's going to capture your sweat in your micro pores in your skin.
- 25:29And then you lead that sweat into two channels.
- 25:32One channel, which is the orange channel that fills up in a zigzag form.
- 25:37It's the volume of sweat you're producing.
- 25:39The other channel is a slightly bar on the lower side that will react in colors to reflect the amount of sodium that is in your sweat.
- 25:52And those two things, they will be super critical to understand how much fluid you're losing from your body while you're performing some sports activity and the concentration of sodium you're losing as well.
- 26:06Because sodium, as everybody knows, it's critical for the performance of muscles, the potassium sodium pump that exists and control all muscles.
- 26:16So learning about those things can help you improve your performance.
- 26:21And of course, this is more impactful if you are a professional athlete, but I think everybody can benefit from it.
- 26:27And the biggest challenge was to take that out of the lab where you mentioned, Michael, where you have an apparatus that is easier to capture all the signals and bring that out in the field where anybody can use under any conditions.
- 26:44And that was the challenge that we took up to help Gatorade to achieve that.
- 26:48And it's had a lot of obstacles for us to overcome.
- 26:53And Python was super helpful because not only it had the tools for us to build APIs, but also there's a ton of formulas that we need to compute to achieve that.
- 27:04And Python had NumPy, Pandas, and Stats, and all the tooling that we needed to make it happen.
- 27:12So let me just describe this really quickly for people who are watching.
- 27:16It's like a band-aid, maybe two and a half inches.
- 27:20Yeah, like four fingers.
- 27:21Three or four fingers, something like that.
- 27:22Maybe about the size of the palm of most people's hands.
- 27:25You stick it on to your arm and it changes these colors and reads out.
- 27:30And then you scan it with this iOS app and it gives you an analysis that you're talking about here.
- 27:35Yeah.
- 27:35Exactly.
- 27:36The app, of course, serves for other purposes as well.
- 27:39So you can like track your workouts.
- 27:41It does integrate multiple sources of information.
- 27:44Garmin, Strava, HealthKit.
- 27:46And then it creates this timeline of events in your day that understands if you're like doing multiple workouts a day, very early in the morning, very late on the evening, and how they interfere in each other.
- 28:00Because if they are too close apart, maybe you shouldn't drink anything between the two of them.
- 28:04If they are too far apart, maybe you need supplemental hydration.
- 28:08So all of those effects, we perform that analysis in Python at the back end.
- 28:12And the app becomes like the avatar that conveys that information to the athlete in real time.
- 28:20Yeah.
- 28:20When I first heard about this, I thought it specifically would just be like, well, Gatorade recommends this.
- 28:24So here's how much Gatorade you should buy.
- 28:26You should get the lime flavor, not the cool or whatever.
- 28:29But it takes in data from, like you said, like Apple HealthKit and Garmin and these other things as well.
- 28:36How do you get that data out of it?
- 28:37That's a great question.
- 28:38So the plan was to go as broad as possible.
- 28:41We even investigated Fitbit and other providers.
- 28:44But for the MVP, we went for three sources.
- 28:49Two external sources, Strava API and Garmin API.
- 28:53So if you're a Strava user or a Garmin user, you can, in a web view, connect to Garmin and Strava through our app.
- 29:00And then we created this data feed from Garmin and Strava into our system.
- 29:06Like some OAuth.
- 29:07Backend sort of API type of thing?
- 29:09Okay.
- 29:10Yeah.
- 29:10And then it starts popping up in the app.
- 29:12You don't need to.
- 29:13The app becomes a read-only thing.
- 29:15You just look into it and you perform your exercise.
- 29:18But the information comes by through the backend.
- 29:21So these are the main channels.
- 29:22So these are the main channels.
- 29:22But we also talk to Apple HealthKit, the platform in the iOS that consolidates information from multiple apps.
- 29:32Health related, of course.
- 29:34And then in that case, if you have like a sleep tracker or other sports tracker.
- 29:39For example, I use RunKeeper.
- 29:40So I go to that application.
- 29:43I allow that application to export information to HealthKit.
- 29:46And then, of course, Apple Health, the app, will see it.
- 29:50But also any other app registered as a reader for the HealthKit platform.
- 29:56And that's how we grab and consolidate all your activity, sleeping and workouts, into this single timeline.
- 30:04And then we provide recommendations on top of that.
- 30:07Right.
- 30:07So you might be able to correlate workout with sleep.
- 30:10Yes.
- 30:10How well you're sleeping or something like that.
- 30:11Yes.
- 30:12That's one of the things we do.
- 30:13That was one of the challenges.
- 30:15Dealing with this events timeline became this, we needed a time series database to do time series analysis.
- 30:22Because time is super relevant.
- 30:24We have to handle conflicts.
- 30:25Because you may have like many trackers reporting the same thing.
- 30:30So the same physical event comes as multiple digital events.
- 30:34Sometimes there are applications that break up a single event into multiple events.
- 30:39Sleep trackers typically do that.
- 30:42So for us, you have a single night of sleep.
- 30:45You go to bed and you wake up.
- 30:47Right.
- 30:47But actually what happens is multiple cycles of sleep that you wake up in the middle of night.
- 30:53But we don't handle them logically as multiple sleeping periods.
- 30:58For us, logically, it's a single sleeping period.
- 31:00So this is another thing we have to handle in the system.
- 31:03Yeah.
- 31:03It seems really useful, actually, the more I hear about it.
- 31:05So let's talk about some of the tech behind the scenes for this one.
- 31:09Cool.
- 31:09There's probably some data science side.
- 31:11There's obviously the API and database side.
- 31:14What do you got going on here?
- 31:15Okay.
- 31:15So in the beginning, we went down to GSSI, the Gateway Sports Science Institute.
- 31:20And together with their scientists, we started to create a model.
- 31:24Not only for the way the sweats patch works.
- 31:28The sweats patch was developed by a Boston company named Epicor, the physical patch.
- 31:33And also the driver that kind of captures the basic information from the patch.
- 31:39That is embedded on the mobile app.
- 31:41And then when you take a picture of the patch, we do some image processing and we extract the two bits of information that we want.
- 31:49The volume channel.
- 31:50That's probably something like Swift or something on the app, right?
- 31:53Today, it's a C# Xamarin.
- 31:55But it was a modern restriction from PepsiCo.
- 31:59They were already using that technology.
- 32:01And it was supposed to be a framework cross-platform.
- 32:05So later, when we decide to go to Android, it would be a possibility to reuse that framework.
- 32:11So that was a constraint that we had to accommodate for.
- 32:14But those modules are Objective-C and Swift, for sure.
- 32:19They are native.
- 32:20Yeah.
- 32:20And so what we do after we have that, we have to translate whatever you read, which is your local sweat rate.
- 32:28How much your forearm is sweating.
- 32:30A single micropore in your forearm.
- 32:33And we have a statistical model developed by GSSI to translate that into your whole body sweat rate.
- 32:40So that is the first machine learning, statistical learning bit that is embedded on the system.
- 32:47And we need to take into consideration what's the weather like?
- 32:51What's your weight?
- 32:53What type of sports you are doing?
- 32:55What's the humidity?
- 32:55Yeah.
- 32:56Humidity we are not using right now because it's hard to capture.
- 32:59So we had to create a less accurate model.
- 33:02But for sure, humidity is critical.
- 33:04But it was a product decision to leave that one out.
- 33:08Because of the facility to grab the information, to capture that.
- 33:12Right, right.
- 33:12And once we have your whole body sweat rate, that acts as a crystal ball for future workouts.
- 33:20So when you're performing a new workout, you don't need to use the sweat patch again.
- 33:24You can use the sweat profile, the crystal ball, to predict, given the conditions of this new workout, how much you're going to sweat.
- 33:33And then base recommendations on that.
- 33:36So, of course, if there are some constraints that if they do not match, you have to do a new sweat test, create a new profile for those new conditions.
- 33:46For example, I create a patch for running and now I'm doing bike.
- 33:50So it's a different activity.
- 33:51It should be best if I create a new profile.
- 33:56This portion of Talk Python To Me is sponsored by Linode.
- 33:58Visit talkpython.fm/Linode to see why Linode has been voted the top infrastructure as a service provider by both G2 and TrustRadius.
- 34:07From their award-winning support, which is offered 24, 7, 365 to every level of user, to the ease of use and setup,
- 34:14it's clear why developers have been trusting Linode for projects both big and small since 2003.
- 34:20To pull your entire application stack with Linode's one-click app marketplace or build it all from scratch and manage everything yourself with supported centralized tools like Terraform,
- 34:30Linode offers the best price-to-performance value for all compute instances, including GPUs as well as block storage, Kubernetes, and their upcoming bare metal release.
- 34:40Linode makes cloud computing fast, simple, and affordable, allowing you to focus on your projects, not your infrastructure.
- 34:48Visit talkpython.fm/Linode and sign up with your Google account, your GitHub account, or your email address, and you'll get $100 in credit.
- 34:56That's talkpython.fm/Linode, or just click the link in your podcast player's show notes.
- 35:01And thank them for supporting Talk Python.
- 35:03How does the app know what you're doing?
- 35:07Do you tell it?
- 35:08Just right now I'm doing this, so take a scan.
- 35:10You have two options.
- 35:11One of them, the app asks the user, when you're scheduling manually a workout, you can say, I'm planning to use a sweat patch on this particular workout, so be prepared.
- 35:21That's one option.
- 35:22The other option is, after you finish a workout, the app asks you, did you use a sweat patch?
- 35:28So if you did, let's go with the flow of scanning.
- 35:31If you're not, there is a fallback mechanism called way in, way out, where we can compare your rates and subtract them and see how much fluid you lost.
- 35:42The downside of this is that we do not capture sodium loss.
- 35:46So you cannot take sodium in consideration.
- 35:48So when it gets to the server side, what's the API framework?
- 35:53So the app is talking to the backend all the time.
- 35:56We kind of use the backend for frontend metaphor of sorts.
- 36:00So the API not only does the reasoning for the whole system, but sometimes it even helps the app a little bit with layout.
- 36:09So the app talks to the backend to get user profile, to get the timeline of events, and then it renders those timeline of events, captures additional information, for example, your motivation and your fatigue, and reports that information to the backend.
- 36:24The sweat scans and manually schedule workouts.
- 36:28Everything else happens at the backend.
- 36:30By everything else, what do we mean?
- 36:32Grabbing weather information.
- 36:34So translating your latitude and longitude into a temperature, if your workout was outdoor.
- 36:40One thing.
- 36:41Sending push, scheduling push notifications to remind you that you have this recommendation or there's an upcoming workout.
- 36:49Things like that.
- 36:50It also computes the local to whole body transformation.
- 36:54It manages your sweat profiles and it triggers some product recommendation engines that will tell you not only Gatorade products,
- 37:03but also general foods that could be suitable for your nutritional needs.
- 37:09So we can say, for example, if you need this amount of carbs, this amount of protein, maybe you should take a little bit of caffeine or casein.
- 37:18And then we give it a list of generic food like rice, coffee.
- 37:24And then you can plan accordingly to fulfill those recommendations.
- 37:28All of that comes from the backend.
- 37:30And the backend is Flask?
- 37:31The backend is Flask.
- 37:33We were in doubt in the beginning being between FastAPI and Flask.
- 37:38I wanted to fight the problem domain, not the technology.
- 37:44So I decided to go fully synchronous.
- 37:46And because in that case, it's super easy to debug.
- 37:49It's much less prone to like problems.
- 37:52I was not concerned with performance in the beginning.
- 37:54What we learned was that Flask was performance enough for all our needs.
- 38:00So that went well.
- 38:01So that went well.
- 38:02We had a separate API just for integrations with Garmin and Strava.
- 38:06After we entered production in March, we realized that the team was too small to maintain it.
- 38:13So we merged the two APIs into a single monolith.
- 38:18But those two APIs, one of them was asynchronous.
- 38:21So we did that asynchronous API with Quart.
- 38:24And that was the one talking to Garmin and Strava because that one was purely IO bound, not CPU bound.
- 38:31Right.
- 38:31You're entirely waiting on Strava and Garmin and the internet.
- 38:36And so you should be able to scale that many, many times out because all you're doing is waiting on their APIs.
- 38:41And you're completely at the mercy of their performance picture as well.
- 38:46Right.
- 38:46So Async makes a lot of sense, but it turns out it wasn't needed.
- 38:49Yeah.
- 38:50The thing that we realized was that, of course, there are tradeoffs.
- 38:53So if you go for a job interview and you present that as like a conceptual problem, I think the answer is no.
- 39:00Do it asynchronously.
- 39:01Do it as a separate API because then you can scale independently.
- 39:05You have better IO throughput, lower latency, etc.
- 39:08But in the real world, you have to balance all those things with the size of your team, the resources that you have, other external conditions.
- 39:17So in the end, we decided to consolidate everything into a single technology in a single stack because it was simpler.
- 39:25If we need to like to onboard new people trained instead of knowing Flask and Cart, now they only need to know a single framework.
- 39:33And because scalability was not a problem, we were using like Kubernetes in production and it's like horizontally scalable.
- 39:40We decided to reverse that and build a monolith, single stack, Flask all the way.
- 39:47And that's what we have today.
- 39:49How interesting.
- 39:49So you decided you can just solve it by running more worker processes for container and then just running more containers if you need to.
- 39:57Exactly.
- 39:57That was a better solve for the conditions we had in the project.
- 40:01I think that makes a lot of sense.
- 40:02There's so often these recommendations of using microservices, breaking stuff into a bunch of pieces, having just the right technology for just this slice of what you're doing.
- 40:15And then you've got your app.
- 40:17Your app is talking to the different services.
- 40:19Now you're trying to coordinate.
- 40:21It just gives me chills to even think about it.
- 40:23Releasing this through the Apple app approved process and coordinating that with the versions of multiple APIs.
- 40:29Exactly.
- 40:30That sounds so bad.
- 40:31It becomes a nightmare really fast.
- 40:33And in my mind, my experience is that microservices is an answer for a given team size.
- 40:40So if you have like 100 developers like, I don't know, or a thousand developers like Netflix or Shopify, then it makes every sense in the world to break it up in individual components because you have individual teams.
- 40:53Conway's law, right?
- 40:55The software you build reflects the architecture of the people in the company and how they build the software.
- 41:02But when you have a very tiny little team, the monolith is great.
- 41:05It simplifies everything.
- 41:07So that's like a lesson we learned that we kind of over-engineered in the beginning, trying to go with two APIs, and we took the route of bringing the monolith.
- 41:19I think that makes a lot of sense for small teams.
- 41:21And here's the thing, if you run into performance problems that really needs async stuff, you know, when you considered to use Flask and not FastAPI, FastAPI was brand new.
- 41:31And who knows if it would survive another six months or if it would go the way of other really promising projects like Jepronto or something, which as far as I could be wrong, but as far as I know, it hasn't gotten a ton of traction.
- 41:44It was really exciting for a while, and it just kind of fizzled out, right?
- 41:47Yes.
- 41:48You want to build on that.
- 41:49So I think Flask is a totally reasonable choice.
- 41:51But I guess what I was going to say is, you know, it's not that different if you need to re-translate that, if you're going to convert that to FastAPI.
- 41:57Like, that's a thing you as a team of a couple of people could do in a few days.
- 42:02Yes.
- 42:02And it would be fine.
- 42:03There were other, like, circumstances.
- 42:05For example, as a big fan of Talk Python To Me, I watched the episode on FastAPI.
- 42:11I watched the episode on Pydantic.
- 42:13And I knew of the symbiosis between the two of them.
- 42:16But for us, we started with Kerberos as a schema validation technology.
- 42:22Which comes out of the Eve project from my friend Acola, by the way.
- 42:25Yeah.
- 42:25And we evolved into using Marshmallow, replacing Kerberos.
- 42:29We compared with Pydantic.
- 42:31And at the time, we didn't want to, like, extract Pydantic from FastAPI and use FastAPI with Marshmallow.
- 42:38So we went with Flask that was, like, not opinionated about what the schema should look like.
- 42:43And we went with Flask and Marshmallow.
- 42:46Nice.
- 42:46Some other interesting building blocks that you highlighted is Pint, P-I-N-T for units.
- 42:53Pint is super cool.
- 42:54Tell people a bit about Pint.
- 42:55Exactly.
- 42:56So one of the things that we're doing on this particular project was it's supposed to be international.
- 43:03And it's, like, heavy on the physics.
- 43:05So we're dealing with rates and concentrations.
- 43:09There's a lot of chemistry going on.
- 43:12We're talking about the metric system, U.S. customary, imperial systems.
- 43:17So converting between units was going to be a big part of the system.
- 43:23And then we find out about Pint.
- 43:25I was, like, in the Pint community for over 20 years.
- 43:28I shook hands with Guido von Russell in 2005 when I translated his tutorial to Portuguese.
- 43:35But I never heard of Pint in those 20 years.
- 43:38But when I had the need, I did a quick research and I found exactly the solution that we wanted.
- 43:45So Pint uses the excellent object orientation that we have in Python to transparently create
- 43:53this, like, new integers and floats.
- 43:55They're just not numbers.
- 43:57But they also have a unit together with them.
- 44:00It's so fantastic.
- 44:01Let me maybe describe this little example on the Pint homepage.
- 44:04So if I wanted to have three meters plus four centimeters, instead of saying three times 100 plus four or vice versa, you know, divide by 100.
- 44:13You have three times meter plus four times CM.
- 44:18And then what you get back is a quantity, which is 3.04 meters.
- 44:21It's fantastic.
- 44:22Exactly.
- 44:23You could even do something horrible like three meters plus seven inches if you had to.
- 44:27And it becomes even more powerful when you're talking about different kind of dimensions.
- 44:32For example, if I want a concentration and I'm going to like to divide mass per volume, and then I need to make sure that my calculation makes sense.
- 44:42So Pint allows you to do that.
- 44:44So you do those conversions and the units are preserved.
- 44:49And because the units are preserved, it's easier to test.
- 44:52It's easier to compute.
- 44:53So it's really a lifesaver that saves us a lot of time while coding this API.
- 45:00Yeah, this is not something that in my world I do anything with these days, really.
- 45:05But if I did, boy, I'd be all over Pint.
- 45:07That thing's cool.
- 45:07Also, there was Unit.
- 45:10Yes.
- 45:10I've also just recently heard about, and I don't know really how they can, UNYT, but this is also something similar in that regard as well.
- 45:20Yeah, we, at the time, and I'm talking about early 2020, we evaluated a couple.
- 45:26I don't remember if Unity we checked, but there were three others besides Pint.
- 45:33But in the end, Pint sound the most robust one.
- 45:36But I'll check Unity again.
- 45:37Yeah.
- 45:37I guess, what's your assessment now that you've been actually using Pint?
- 45:41It's good?
- 45:41We're super happy.
- 45:42If we have like zero issues with Pint, it saved our lives time and again.
- 45:47Yeah.
- 45:47Another one that you'll run into is Time.
- 45:49So you used Pendulum for that.
- 45:51I was even a little bit resistant in the beginning because I was using date time forever.
- 45:57And of course, members of my team were suggesting, hey, why don't we use Pendulum?
- 46:01It has a really nice interface.
- 46:03And the deal breaker for me was that the Pendulum object, it inherits from the regular daytime objects.
- 46:13So they are completely interchangeable.
- 46:14The one thing I didn't want to happen was to have like these two kind of libraries dealing with time.
- 46:21And in that case, daytime is standard in the standard Pint library.
- 46:26Something else external would be a cause of concern for me in my experience.
- 46:32But in that case, it was seamless.
- 46:34So I can use either Pendulum or daytime.
- 46:36It doesn't matter because they all inherit from the same root.
- 46:41So that was key.
- 46:42And to be honest, it was convenient, especially for time zones.
- 46:48But remember that that was before, I think it was on Python 3.9, that we had better support for time zones.
- 46:56And at least in the standard Python.
- 47:00And at that time, I think Pendulum was having a better way to handle with time zone conversion.
- 47:06That was key for us in terms of the solution.
- 47:09We never know where our athletes are going to be in the world.
- 47:11So that was the key reason.
- 47:13And we're happy with Pendulum.
- 47:16Yeah, this is super neat.
- 47:17You know, I didn't really put it together when I was looking at this before, but the time zone stuff is quite interesting.
- 47:22Like something that's always a challenge that I deal with is when I'm working with some of the web apps that I have,
- 47:30or other things, just where is the server versus where is the person accessing the server?
- 47:37And it turns out to be way more annoying than you think, right?
- 47:40Like another thing we're going to talk about is using MongoDB for the backend on this.
- 47:44And so am I.
- 47:45And I'm just a super fan of MongoDB.
- 47:47It's been such a nice way to make fast, easy to maintain apps.
- 47:51But it stores stuff at like UTC, whereas the server, I think, is in Eastern time zone.
- 47:56And I'm in the Pacific time zone.
- 47:58And so if I want to pull something up, so this event is going to happen then, or it happened at what time?
- 48:02It's not easy to say, well, that was an hour ago.
- 48:06Like something so simple as here's a list of activities.
- 48:08And this one was an hour ago.
- 48:10It's challenging.
- 48:10And this is really cool.
- 48:11So you can say, instead of daytime now, I can say pendulum.now and then pass in the base time zone.
- 48:16And I say, well, what is now in, you know, inbound time zone or something like that, right?
- 48:21Would be really, really nice.
- 48:22The strategy we took, which is kind of traditional strategy, is that at all the edges of the system, we convert to UTC.
- 48:30And inside, we're just reasoning on UTC.
- 48:34And only when we're kind of exporting information through this membrane of the system back to close to the user, then we translate back to their time zone.
- 48:43However, it gets tricky when we're talking about not real time, but nominal time.
- 48:49What is nominal time?
- 48:50For example, I wake up at 7 a.m.
- 48:54So 7 a.m. for me, it's a nominal time.
- 48:57It's not anchored on any place on Earth.
- 49:00It's like the time that I'm supposed to wake up.
- 49:04The nominal time becomes trickier because it's not anchored on a particular place.
- 49:10So you have to deal with those kind of things a little bit differently.
- 49:13But other than that, Pendle was very ergonomic in terms of their API.
- 49:19It's super easy.
- 49:20You can keep it on your mind.
- 49:22And it's compatible with date time.
- 49:24So it was a plus.
- 49:25We're happy.
- 49:26That's a really neat point because if you've got some other API that takes a date time, you can just pass in the Pendle time and it just, it is a date time.
- 49:35Yeah.
- 49:35Right?
- 49:35So you don't have to major, oh, I forgot to convert here.
- 49:38So it's broken.
- 49:38So the lander crashed into the ground because, you know, whatever.
- 49:41Exactly.
- 49:42All those units and conversion types are weird.
- 49:44Yeah.
- 49:44And the arithmetic.
- 49:45Right?
- 49:46So I think that is the other aspect that Pendle makes a little bit easier.
- 49:50The arithmetic one is like, as a day subtract minutes, this duality between a point in time and a delta that we do have on like the time and time delta and all the Python API.
- 50:03But Pendle also helps you in that sense to do those conversions in terms of like scale and arithmetic.
- 50:11So it was really interesting.
- 50:13Yeah.
- 50:13One quick thought I'll throw out there that because this was such a surprise to me.
- 50:16I just had, it's so undiscoverable, but it's good once you know it.
- 50:21Yeah.
- 50:21It's good to know it.
- 50:22Let's put it that way, at least.
- 50:23That when you're doing, forget Pendle for a minute, if you're just doing raw date times and time deltas.
- 50:28So time deltas always have a seconds, right?
- 50:31Yeah.
- 50:31So I create a time, a difference between two times or I take a time and add a time delta.
- 50:36I get a new time delta or you get new time.
- 50:38But if you have a time delta and it's in seconds, which is basically the only option you get.
- 50:42And you want to know, well, I need this in hours.
- 50:45I would always just go two total seconds divided by 60.
- 50:48Exactly.
- 50:48Divided by 60 again.
- 50:50What you can do is create another time delta and say time delta hours equals one and then divide one by the other.
- 50:56And then you get a number of hours.
- 50:59Or if you want like weeks, time delta is seven days and you divide your time delta by that and it'll give you the days.
- 51:05And that's really handy.
- 51:06But boy, is it hard to discover to know that that's possible.
- 51:09Exactly.
- 51:09And that's where I think Python shines as well.
- 51:13Because since the beginning, one of the arguments in favor of Python, it was when people said Python is pseudocode that runs.
- 51:22They were telling you Python brings you closer to the domain of the problem.
- 51:26Right.
- 51:27And that matters.
- 51:29Syntax sugar matters.
- 51:31Because the way you express software, it means you make less mistakes.
- 51:36So when you read it, you fully understand it.
- 51:39Yeah.
- 51:39It's easy to do a review.
- 51:41It's easy to do maintenance.
- 51:43It's easy to throw in and write it again.
- 51:45That matters.
- 51:47So it's not just about if you know the logic, if you know the theory, but in the way you express the logic and the theory matters a lot.
- 51:56Absolutely.
- 51:57Totally agree.
- 51:57All right.
- 51:58Let's talk one more element here on this one.
- 52:03And that's the database side of things.
- 52:05Why did you choose MongoDB?
- 52:07What's your experience working with it?
- 52:09That's a great question.
- 52:10That's an example.
- 52:10That's a great question.
- 52:11So I came while I was at the university, I was working with the database group and I had a lot of experience with like database.
- 52:19I played with object oriented database in 1993, the French object database called O2.
- 52:25As time went by, we had Zope and ZODB.
- 52:29I played a lot with ZODB.
- 52:31I even made a tiny little contribution to Zope.
- 52:33So I've been exposed to NoSQL before NoSQL became a thing.
- 52:38But of course, SQL was still there.
- 52:40But what we wanted was, again, development time.
- 52:44So as a director at Working Co., my main consideration is, can I make this project fit the budget and the schedule before I exactly know what we have to do?
- 52:55Because details will only be captured at the end of the conceptual design phase.
- 53:01But at that point in time, the money is defined, the schedule is set.
- 53:06So it's like, okay, I'll build the pyramids, but I don't know what's going to be like bringing those blocks of rock across the Nile.
- 53:13So because of that, I wanted to go for flexibility first.
- 53:17And going for a NoSQL database, it gives you speed in terms of development time, right?
- 53:24So you can put anything in there.
- 53:26Mongo is storing information in the same formats as the applications are consuming then, which today are like...
- 53:34You don't have that object relational impedance mismatch.
- 53:37You just have it's in Python.
- 53:38Now it's in Mongo.
- 53:40Now it's back in Python.
- 53:41It's the arms of the world.
- 53:43I always was let down by arms.
- 53:47Because in the beginning, when you know nothing, they are great because you don't need to learn the actual language of the database.
- 53:54After you evolve, they become a barrier because they are never as sophisticated as the data manipulation language of the database, right?
- 54:05And then you say, oh, why they don't support this and that?
- 54:08My challenge has been more operational with ORMs is they're pretty good.
- 54:13And a lot of times, if you have the right indexes, you know, the speed can be okay.
- 54:16If you make sure you do the joins instead of the lazy N plus one type of queries, you'll be okay.
- 54:23But you build up your classes and everything's easy.
- 54:25And then you want to add a field to a class.
- 54:29You want to create a relationship.
- 54:30Well, now you try to run your app.
- 54:32It doesn't just not work well.
- 54:33It fully crashes until you do a database migration.
- 54:36And are you doing that migration in production and staging and dev?
- 54:41And then what's the downtime story as you roll out the changes to your multiple servers that all got to talk to that database?
- 54:47It's like, ah.
- 54:48And for me, something like Mongo that is just so much more likely to adapt.
- 54:52Like I haven't run a database migration or anything like that for years.
- 54:57You know, people talk about Mongo for like it's web scale and it's all this data.
- 55:01And that's great.
- 55:01I mean, like my database probably has seven gigs of data for like talk by done training and the podcast.
- 55:07And that's a non-trivial amount of data, but it's not so much about the data.
- 55:11It's about the flexibility.
- 55:12Like it's easy to make it fast and it doesn't require DevOps at the extreme to do it well.
- 55:19You know?
- 55:19That is a great point because managing the database.
- 55:22I mentioned DevOps.
- 55:23So because Mongo, they also provide the Atlas service where you have like database as a service.
- 55:29That was key for us because then we can like forget about this.
- 55:33We simply connect to Atlas.
- 55:34They manage our cluster.
- 55:36They have the dashboards, everything in place.
- 55:38It was one click of a button to migrate from one version of Mongo to another version of Mongo.
- 55:44So those things are priceless when you're doing like quick-paced development.
- 55:49There was another reason though.
- 55:50In the beginning of this project, PepsiCo asked us to use Azure.
- 55:55So that meant we were doing our Python services within Azure and we had to do a database within Azure.
- 56:02And we went for CosmoDB because CosmoDB was compatible with Mongo.
- 56:07If at any point in time we needed to move out of CosmoDB, we would have Mongo as a fallback.
- 56:12And that's exactly what happened.
- 56:14So a couple of months, there were some political changes within PepsiCo.
- 56:19They decided to go like AWS out of Azure and then boom, we had MongoDB in Atlas and we had like the same cluster in AWS for Python.
- 56:30We were happy.
- 56:31Totally agree.
- 56:31Fantastic.
- 56:32So I know we're going to talk about a bunch of APIs, but we spent all our time talking about this one.
- 56:38Sure.
- 56:38But I think this is really a super interesting thing to dive into.
- 56:44We can touch on some of the other ones maybe a little bit, but I guess before we move off of this,
- 56:48like what's one of the big takeaways you took from this project here?
- 56:51Oh, that's such a big question.
- 56:53There are like many things.
- 56:55The biggest perhaps is at the core of the agile mindset.
- 57:00After you implement stuff, it's really when you start to understand the problem.
- 57:05It's really, really hard to kind of design on paper and then it just works.
- 57:11So what we did for this project was many, many cycles of software rewrite.
- 57:17When the project started back in 2019, like over the weekend, when they presented me the problem over the weekend, I was able to, on a Friday afternoon, Saturday and Sunday, to work on a tiny little full-blown solution.
- 57:32I had a timeline.
- 57:33I had a recommendation system.
- 57:35I had recommendations.
- 57:36It was kind of mockery a little bit, but I was able to cook that up in three days, show that to the clients and say, this is more or less what you're going to do.
- 57:47And they really understood what was in there.
- 57:49And then we threw all of that away and built like the new version, like on Troy, many cities built one on top of the other.
- 57:56So that's what happened on this API.
- 57:58Like we're doing microservices, like let's do Monolith.
- 58:02We're doing Cosmo.
- 58:03Let's do Mongo.
- 58:04We're doing Quartz.
- 58:06Let's just do Flask.
- 58:07We're doing Kerberos.
- 58:08Let's do Marshmallow.
- 58:10Being able to throw things away and kind of rebuild, refactor, the power of refactoring made us to have a system that's always performing, that's manageable, that's minimal technical debt.
- 58:24And I think that was the key learning that I was able to fully apply in this long-term projects, like two years.
- 58:31That is not common for a working coach to have this two long projects.
- 58:36Usually our project is like three months, six months, maybe a year.
- 58:39But in the case of Gatorade, it's a retainer project.
- 58:43We're for the long run with them.
- 58:45And in this case, you really need to evolve the platform.
- 58:49It's like maintenance-driven development.
- 58:52Does that actually give you a different mindset when you're creating?
- 58:55You're like, I am going to have to live with this.
- 58:58Not they.
- 58:59We're going to have to live with it.
- 59:00I think that is the most difference between what I consider seasoned developers and new developers.
- 59:09We have like junior developers that they are very competent.
- 59:13They are very capable.
- 59:15They master really quickly new technologies.
- 59:18But the difference is to fully understand the impacts of decisions, not just based on theory, but based on social events that may or may not happen, based on what the future may bring.
- 59:30And experience counts a lot in that sense.
- 59:33And the maintenance-driven development mindset, when you know you're the one that you're going to do the maintenance, changes things a lot.
- 59:42You think about stability, robustness, task coverage in a completely different way.
- 59:48I totally, it seems like it absolutely would if you're the one who's got to live with it.
- 59:52Because you go to some of these consulting projects and they're like, oh, we really want to use this specific database.
- 59:57We want to use this framework, but in this odd way.
- 1:00:00And you're like, well, they're the customer.
- 1:00:01They're always right.
- 1:00:02But if it's going to be you, you're like, yeah, we better build this the way that we're going to be happy in a year.
- 1:00:06You know, there's that, it reminds me of that funny quote, like, always code as if a person who ends up maintaining your code will be a violent cycle path.
- 1:00:15That's where you live, right?
- 1:00:16Very good. That's good advice.
- 1:00:17Yeah, a little bit morbid, but do think about that you'll have to live with it, I guess.
- 1:00:23And I think that talks to the trend they call boring codes, right?
- 1:00:27There's a bunch of like speeches and talks on the internet.
- 1:00:30People talk about, oh, right, boring codes.
- 1:00:32Codes are easy to understand, easy to do maintenance.
- 1:00:34It has this mindset that when you're learning things and you're not concerned about production stuff, you are much more bold to try new things, right?
- 1:00:45Because then the project is done, you move away.
- 1:00:48So there's no cost, there's no risk, there's no penalty for trying new stuff that may prove inadequate.
- 1:00:56But when your success measurement is considering the maintenance phase, the long-term success of the project, the mindset is a different one.
- 1:01:05It's what is stable, what's guaranteed.
- 1:01:08If you're chasing the shiny new thing, you could end up saying, well, I'm going to build this six-month project.
- 1:01:12I'll do that in React.
- 1:01:13And this one is going to be in Vue.
- 1:01:14And this one will be in Angular.
- 1:01:15And this is going to have this backend and that backend.
- 1:01:17And then all of a sudden, you end up maintaining every JavaScript front-end framework in the world.
- 1:01:22Exactly.
- 1:01:23And yeah, you don't want to be like that.
- 1:01:25I think the other thing you touched on is really interesting.
- 1:01:28One of the things that I try to preach a lot is it often doesn't matter too much how you get started so much as you get started on a project.
- 1:01:37I see a lot of people saying, you know, they'll get frozen.
- 1:01:40They're like, well, I just can't decide between Django and Flask or FastAPI or this or Postgres or Mongo.
- 1:01:47And they just, they think and they think and they think and they don't get anywhere.
- 1:01:51Like you highlighted with your, I did it over the weekend prototype.
- 1:01:54A lot of times those people who are stuck, if they just fully internalize, like you can just go on a path and then evolve it with refactoring and change it and throw it away and rewrite it with more knowledge.
- 1:02:05The time you spent worrying about what to do, you would already have a working example, probably.
- 1:02:09And then you have so much more information to build from and decide from.
- 1:02:13I think that's a really important takeaway.
- 1:02:15God is in the details.
- 1:02:16Nobody stumbles and mouthings.
- 1:02:18It's the little things that make your fault.
- 1:02:20That's a good quote.
- 1:02:21I like it.
- 1:02:22Nice.
- 1:02:23All right.
- 1:02:23Well, I think rather than diving into the other APIs that we're going to cover, I think maybe just this deep one into the DXSWet patches is probably a little bit more constructive and useful.
- 1:02:34So maybe we'll leave it here for the APIs.
- 1:02:36Cool.
- 1:02:36Really, really neat work.
- 1:02:37A lot of moving parts, right?
- 1:02:39You've got your mobile apps.
- 1:02:40You've got your mobile apps in Xamarin.
- 1:02:41You've got your ML models.
- 1:02:44You've got the APIs, the other external API integration, the other app integration.
- 1:02:49A lot of stuff going on here, right?
- 1:02:50So I think it's a pretty good case study.
- 1:02:52It is.
- 1:02:52One bit that we didn't mention, I'd like to really quickly mention, is that we have another engine for product recommendations that use constraint problem solving.
- 1:03:04And this was, we're reusing a module, a colleague of mine called Gustavo Niemeyer.
- 1:03:10He's a core developer for Python, now working for Canonical.
- 1:03:13And he was with me in EuroPython 2005.
- 1:03:17And on EuroPython 2005, he presented a Python module that now we're using to solve those constraint-based problem optimization.
- 1:03:26And that was really cool because it's a really powerful mechanism.
- 1:03:30And the problem we were solving was that you have all of these needs, right?
- 1:03:35Needs for carbs, needs for protein, needs for hydration, needs for electrolytes.
- 1:03:40And then you have all of these products that have different combinations of those elements.
- 1:03:45So what is the optimal amount of products and types of products?
- 1:03:50And what is the minimal amount that you need to kind of fulfill all your nutritional and hydrational needs?
- 1:03:57And for that, we use Python Constraint.
- 1:04:00There are other engines there, but we want it to be like fully Python solution.
- 1:04:05And that is another hint that I want to share with people.
- 1:04:09That is, it solves like a big problem and it's really easy to use.
- 1:04:13And this is Python-Constraint on PyPI?
- 1:04:16Yes, exactly.
- 1:04:17This one you have on screen, Python-Constraint.
- 1:04:19Looks really cool.
- 1:04:20It reminds me a little bit of linear programming.
- 1:04:22It is.
- 1:04:22The difference is, well, actually, you have linear programming like simplex, where you're kind of going into the plane and trying to optimize numerically.
- 1:04:32This is one kind of thing.
- 1:04:33This other one is more on exploring a discrete space of solutions.
- 1:04:39So you define your variables, the domain of values for each of these variables, and the constraints that validate, is this combination of values a solution to the problem or not?
- 1:04:50If not, it's refuse.
- 1:04:52So then it's a search space.
- 1:04:54Yeah.
- 1:04:54So there's like a chess problem, the rook.
- 1:04:57Exactly.
- 1:04:58Which clearly is not a continuous problem.
- 1:05:01It's a very discrete.
- 1:05:01The rook can be in one of, you know, 100 places or whatever on a chessboard, and that's it.
- 1:05:06Very cool.
- 1:05:07One final thing on this project here.
- 1:05:09Now that you've created it, how many people are keeping it going and working on it?
- 1:05:14What's the team size at the beginning and the end?
- 1:05:16I mean, we talked about the monolith versus microservices, but not really the details there that made you decide the monolith side.
- 1:05:22That's a great question.
- 1:05:22So first of all, all the time we're talking about the GX consumer.
- 1:05:27So for like you and me, we also have another app that talks to the same API called GX Teams.
- 1:05:33And the GX Teams is for practitioners, coaches, personals, that they are managing a group of athletes.
- 1:05:40So this is another thing that Gatorade launched, I guess, this month.
- 1:05:44Both apps are up to the same API that we call GX Rack Engine.
- 1:05:48So just for GX Rack Engine, our development team is today for people.
- 1:05:55It's me, João Gomes, Nicolas Moya, Rodrigo Merlo, and Sachari Moreno.
- 1:06:01So it's me plus four.
- 1:06:02That is the whole backend team.
- 1:06:05For frontend, for PM, strategy, business, product, then it's kind of gross, right?
- 1:06:13But the things that we talk about in the Python world, we're talking about five people.
- 1:06:18You know, that's super common.
- 1:06:19If we look at the Python developer survey from the PSF and we go down and look at the team size,
- 1:06:24the average team size, 75% of the time was two to seven people.
- 1:06:30Yeah, it's the pizza rule, right?
- 1:06:32Yeah.
- 1:06:32If you get out to what I would call the microservice side, you know, that's maybe 20 people or so.
- 1:06:39And 20 people or more on the team size is only 4% of all software developers doing Python.
- 1:06:45So keep that in balance when you hear about like, you know, how Netflix or Google or Instagram is doing some amazing thing, right?
- 1:06:52That context doesn't necessarily apply to like your context.
- 1:06:55Exactly.
- 1:06:55And they break down.
- 1:06:56I worked for global.com, which is the biggest news company in Brazil.
- 1:07:01We had a audience of 4 million people like daily going through like our websites, etc.
- 1:07:08And the teams internally, they were like four or five people.
- 1:07:13We none above seven because it becomes unmanageable.
- 1:07:17The communication overhead becomes so high that it's not worth it.
- 1:07:22Super interesting.
- 1:07:22And I think we're going to leave it there, but I'm going to ask you the two final questions.
- 1:07:25Before I do that, let me just call out a couple comments from the live stream.
- 1:07:29Go ahead.
- 1:07:29Black and White said, this video is so great to be frank.
- 1:07:31Thank you.
- 1:07:32And Vincent, hello, hello.
- 1:07:33Love your show.
- 1:07:34Keep up the work, please.
- 1:07:35All your guests are on point.
- 1:07:37Very interesting.
- 1:07:37Yeah.
- 1:07:37Thank you all for being here.
- 1:07:39That's great.
- 1:07:39All right, Rod.
- 1:07:40Working on these projects and others, you're going to write some Python code.
- 1:07:44What editor would you fire up?
- 1:07:45Well, that's a great question.
- 1:07:46So I'm a big fan of PyCharm.
- 1:07:48So I've been using PyCharm forever.
- 1:07:51It has some features that I kind of love, like class hierarchy, like usages of functions,
- 1:07:57the debugging.
- 1:07:59It's super well polished.
- 1:08:02So I use PyCharm for professional work.
- 1:08:05But having said that, I use everything else.
- 1:08:08So I dabble with Visual Studio Code, great tool.
- 1:08:12I use Vim a lot when I'm on the shell or doing stuff.
- 1:08:16And of course, I use Jupyter Notebooks as well.
- 1:08:19And sometimes I code stuff in Jupyter Notebooks, straight on Jupyter Notebooks.
- 1:08:23And it's like lots of code.
- 1:08:25All of those.
- 1:08:26Fantastic.
- 1:08:26I agree with all that.
- 1:08:27And notable PyPI package.
- 1:08:30Well, we mentioned like a couple there, right?
- 1:08:32Like Pint and Pendulum and Python Constrain.
- 1:08:37One that I heard in your show and I explored a little bit is called Rich.
- 1:08:42So I think it was Brad Cannon that mentioned Rich, but I'm not sure right now.
- 1:08:46But that was really awesome as well.
- 1:08:49Really interesting.
- 1:08:50So these are like my picks.
- 1:08:52Yeah.
- 1:08:53Rich is coming along as quite an interesting project.
- 1:08:56It's going, you know, Will there is doing such interesting work.
- 1:08:59And it just has super opened up what you can do in the terminal, I think, in a much more
- 1:09:04approachable way.
- 1:09:05Have you seen Textual?
- 1:09:07No, I haven't.
- 1:09:08I think that Textual is like a layout engine for Rich.
- 1:09:11Oh, that's cool.
- 1:09:12That is coming on here.
- 1:09:13So what you can do is you can break up your terminal and to have like a toolbar, like a
- 1:09:19left docking thing, a footer, and then a main area.
- 1:09:22And then you render into each of those with Rich.
- 1:09:25Fancy.
- 1:09:25You can do like even arrow keys and only like move the main window section.
- 1:09:30Oh, it's yeah.
- 1:09:31There's a lot of cool stuff going there.
- 1:09:33So super cool.
- 1:09:33Yeah.
- 1:09:34It's awesome.
- 1:09:34All right.
- 1:09:35Well, final call to action.
- 1:09:36What's your final advice for people building these APIs thinking about these decisions for
- 1:09:41their own projects?
- 1:09:42Well, one I already have given, it's like be hands on, like try it out, see how it feels,
- 1:09:47get your hands dirty.
- 1:09:49This is crucial in my mind.
- 1:09:51The other one is start thinking about maintenance driven development.
- 1:09:54So when you start, because even if it's not you, somebody will have to like give maintenance.
- 1:10:01So at least balance the costs and benefits of exploration and the advantages and downsides
- 1:10:09of reusing well-established technology.
- 1:10:11Right.
- 1:10:12Look for the Zen, the yin-yang, the balance on these forces.
- 1:10:15Good advice.
- 1:10:16Definitely second it.
- 1:10:17Rod, thanks for being on the show.
- 1:10:18Thank you so much, Michael.
- 1:10:19Yeah, you bet.
- 1:10:21This has been another episode of Talk Python To Me.
- 1:10:23Our guest on this episode was Rod Senra.
- 1:10:26It's been brought to you by Sentry and Linode and the transcripts are brought to you by Assembly
- 1:10:30AI.
- 1:10:30Take some stress out of your life.
- 1:10:32Get notified immediately about errors in your web applications with Sentry.
- 1:10:36Just visit talkpython.fm/sentry and get started for free and use the promo code
- 1:10:42talkpython2021 when you sign up.
- 1:10:46Simplify your infrastructure and cut your cloud bills in half with Linode's Linux virtual machines.
- 1:10:50Develop, deploy, and scale your modern applications faster and easier.
- 1:10:54Visit talkpython.fm/Linode and click the create free account button to get started.
- 1:10:59Transcripts for this and all of our episodes are brought to you by Assembly AI.
- 1:11:03Do you need a great automatic speech to text API?
- 1:11:06Get human level accuracy in just a few lines of code.
- 1:11:08Visit talkpython.fm/assembly AI.
- 1:11:11Want to level up your Python?
- 1:11:13We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:11:17Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:11:22And best of all, there's not a subscription in sight.
- 1:11:25Check it out for yourself at training.talkpython.fm.
- 1:11:28Be sure to subscribe to the show, open your favorite podcast app, and search for Python.
- 1:11:32We should be right at the top.
- 1:11:34You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:11:39and the direct RSS feed at /rss on talkpython.fm.
- 1:11:43We're live streaming most of our recordings these days.
- 1:11:46If you want to be part of the show and have your comments featured on the air,
- 1:11:50be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:11:54This is your host, Michael Kennedy.
- 1:11:56Thanks so much for listening.
- 1:11:57I really appreciate it.
- 1:11:59Now get out there and write some Python code.
- 1:12:00I'll see you next time.
- 1:12:21Thank you.