Welcome back to another episode of "This is My Architecture."
Today, I'm joined by Mohan from Purolater.
- Hey, Mohan. - Hi, how are you?
So tell us a little bit about what Purolater does.
Purolater is Canada's largest express courier company.
And we process about five million packages every day.
And we do both business-to-business and business-to-consumer.
And on the B2C side,
we're tied very much to things that happen in the B2C markets
similar to Amazon Prime Day or Black Friday or Cyber Monday.
And as we approach peak now this is our holiday season as well.
And we have a lot of peaks and valleys through the year.
So a lot more online shopping and ecommerce going on,
that's also leading to a lot of digitization.
What were some of the challenges
that you had with your existing system?
You're right.
In our existing legacy system,
we had two problems that we were trying to solve.
One was the reliability of the messages
and two was the scalability of what we had in place.
So how many packages do you process every day?
Yeah, we process about five million packages every day.
But like I said, during our peak times
we do scale up and down.
So it's important that we have that elastic scalability.
Scalability is really important.
- I see a... - Very much.
fantastic architecture that we're going to dive into.
- Tell us how it works. - Sure.
Let's start with the lifecycle of a package.
When a customer declares intent to ship a package,
they produce a label.
And the moment they produce a label
that information is with us in our legacy system.
And what we do is we take that basic information
about a package,
and it's a JSON message essentially.
We take that and process it into an SQS, in a queue.
And a simple Lambda, which we call an ingestion Lambda,
picks it up and essentially drops it into a relational form
into an RDS at the back that we have.
So inventory of your package is really important,
can't afford to lose it.
So using something like SQS gives you that reliability, right?
Exactly.
We have it totally decoupled and scalable
in terms of our queues and our compute.
Okay.
So once you know about the package what's going on over here?
Yeah.
So on a package there is a variety of events
that happen through the package lifecycle.
Typical events that happen are a pickup event
where a delivery or a pickup driver goes
and picks up the package from the customer.
And it travels through our network, through our facilities
and so on and gets to the customer's door eventually.
And through that lifecycle, it goes through, like I said,
a few scans in the facility
as in 'we got the package' in the hub or terminal.
And it's 'out for delivery' and other scans
that we do or an event that happens on the package
and then 'out for delivery' is another one.
And 'delivered' and 'signature required', et cetera
are all these events that happen with the package.
So I see event processing here.
Tell us a little bit about how that works.
Yeah.
Each event, like I was telling you about, has a different connotation
and a different meaning to the company and to the customer.
One of the interesting ones I'll talk about...
The generic event flow goes like this.
Again, every event happens from a handheld
that the pickup or delivery driver has.
And that gets put into another SQS queue.
And another Lambda pulls it off of the queue.
And then, again, processes it
into a relational database at the back.
But each of these Lambdas have a different flavor
in what they do and what purpose they serve.
And that is for a 'pickup' event
the processing is different as opposed to
if you take for example a 'disruption scan'
meaning a truck broke down somewhere in between,
we need to know immediately
so that we can actually let the customer know
in real time that there may be a potential delay
in getting the package.
So each of these Lambdas react differently
to different types of events that happen.
Yeah.
So different queues, so you're actually separating
a lot of your business logic
and not coupling them
given you've got so many events every day.
- That's right.
And of course, you know, you're not worrying about servers.
Everything is completely serverless.
- That's right. - Great.
I see S3 here. What are you doing with that?
This is also an interesting use case for us.
And like I talked about the package travels
through our network,
and we capture several events throughout.
And one of them is something we do in a terminal
called 'redimensioning and weighing.'
So an example would be,
if you had declared a box to be 10x10
and 10 kilograms...
And as it passes through this ORT machine,
we reweigh it, and we redimension it.
So if we were to find that
either the box was bigger or heavier or what have you,
then that image is captured as well as...
How should I say it?
A revenue uplift scan is done on that package.
And that image gets stored into an S3 bucket.
And we take that image or create a link
in our relational database
to that image that was captured and put into an S3.
- All right.
That gives you if you look at this architecture here,
a full view of a package and its lifecycle.
That's very, very critical to our business.
- And you've obviously got a single source of truth
with using RDS across that inventory as it goes.
- That's right. - That's fantastic, Mohan.
What are you thinking about next?
As you rightly mentioned
if we start the process more events and different sets of events,
then we might want to think about
doing some orchestration within that.
And we're kind of looking at
potentially the use of Step Functions.
As well as we would like our...
Since you said that this is our single source of truth
and we rely heavily on it for consumption at the back
is we would like to see if we can kind of isolate the writes
and the reads, and potentially scale the reads,
read notes through, you know, several read copies and...
- So using read replicas over here to help scale this front end.
That's right, exactly.
And we would drive our analytics and any kind of business intelligence
out of those consumers.
So we're looking at doing that in the future.
That's great, Mohan.
It's really good use of event-driven serverless architecture
to go and help your customers deliver packages.
- That's right.
Mohan, thank you for coming in
and sharing your architecture with us today.
You're welcome. Happy to be here.
And thank you for joining us on "This is My Architecture."