welcome back everyone to the devops
track here at pycon online 2021 i hope
you're enjoying the day and all of the
talks that we've had available for you
i've certainly been enjoying this has
been been fascinating it's always
interesting seeing how things come
together as as all this planning that
we've done you don't quite know how it's
going to work out until we're actually
live but it's excellent when we see it
happens and so far we haven't had
anything fall over dramatically um so
there's still time hopefully we can
break something really really badly by
the end of the day it is the devil's
track after all
but here to uh give us our next talk we
have matthew coles who's here to talk
about when a little web app needs to
grow up a journey from a hobby project
to production i'm keen to find out what
this project was and hear about this
journey and uh we have a pre-arranged
signal to make sure that matthew can
come in at the right time so matthew
cacor cacor
over to you
perfect uh read loud and clear so um
yeah like thanks everyone for joining um
pycon my name is matthew coles
i'm working in cloud at the moment so i
work for one of the the cloud technology
companies but i've always been building
apps a lot of the apps that i've built
are kind of like hobby projects weekend
projects um as well as like the ones
that we we have for work as well so this
the story is really about a hobby
project that turned into something a bit
more um hence the name and some of the
learnings that i had with that and and i
guess you know one of the most
interesting things is like how do these
things grow like and and how should you
start because it is quite scary um
you know thinking about building
something from scratch and all the
different things so anyways um
[Music]
considering we're on the dev oops track
the only other thing that i'll call out
very quickly is uh i uh i have yet i
just moved into a new space and i've got
like a whole bunch of stuff half built
in the background um so i didn't manage
to finish everything in my new little
working from home area um so hopefully
that happens next week but yeah
let's get straight into it
so
this uh project that i wanted to talk
about i started with like something that
a friend came and
chatted to me about they said they were
doing an event um they wanted to be able
to have uh some t-shirts that were um
able to be delivered to people that were
attending the event
and the the issue that they had was they
they didn't really trust uh any of the
third parties that had like quick easy
form systems or form solutions that they
could use
the other thing is uh you know like my
friend she was very security conscious
as well
and so she didn't really want to store
much data when it came to the t-shirts
as well she just wanted a form that
would basically send off to a vendor
and so with that i said yeah no problems
i'll treat it like a weekend project and
you can see a shot of my lego on the
side
if i'm not working on side projects on
the weekend i'm usually building legos
this is one of the sets that i built
from i think it was the creators lego
creators
so you can take a look at that there
so i sketched out a rough architecture
of what i thought would be needed for
this application based on those
specifications that she provided you
know i knew that i would be
creating some form of web application
it's probably going to be delivered out
on a server
it's going to have a whole bunch of
different form elements i'm probably
going to need to know like the person's
name their address their phone number
you know what type of t-shirt that they
want what's the size what's the color
i might have some different details and
some of the graphics as well
and you know this this design was was
simply around like let's not have a
database or anything let's just like
take exactly what's entered in that form
and feed it into an email service and
that email service is going to then
notify the end user like the order's
been submitted to that up uh to the
vendor that's handling the t-shirt
orders uh but it's also gonna at the
same time on that same thread also kind
of act as the catalyst for the vendor to
put that order together and ship it out
to the customer so it's fairly simple
but
knowing me and the way that i work and i
think a lot of other people work this
way as well
i
i kind of want all the things when i
build an app so this is kind of like
you know why i wanted to to talk about
this as a topic but you know like i i
could have like massively like um over
overscope this i guess i'm always
wanting to learn certain things i always
have like a backlog of things that i
want to learn i always want it to be a
really cool amazing app and um you know
like that kind of got me thinking on
this weekend before i started the
project like how do i should i have
user's login is that really needed how
do i handle logging should it be
container based should i use docker
kubernetes or something
how am i going to handle like form
validation
like i can have simple validation on
certain elements that are getting sent
to me but do we need additional
validations to uh make sure that user
email address is really an email a valid
email address rather than just being
entered as an email address um are we
going to have to track orders and give
updates to customers like can i make
this nice and slick so i can just like
do a git push have it arrive in my git
repository and then ci cd does all the
things and builds the environment
magically for me uh which is nice
and then the other thing is like you
know i i spent a bit of time with react
i really wanted to build a lot of this
in flask a fort flask would be a really
nice framework to use and i really like
i'm using python as a language but i'm
like you know do i need to have like a
very slick front end should i be doing
react and javascript at the very start
and the last thing is like messaging
queues as well so i send off an order
and it might be action by a system
eventually i might have a database maybe
i need redis for state if i have user's
login and maybe i use it for a couple of
other things as well
do i need an authentication server do i
need monitoring alarming if something
goes wrong like how many times is this
going to be used how how often am i
going to have to actually monitor this
when it comes to
you know the the orders coming in and
making sure that it's up and available
for everyone all the time
uh you can see on the other side as well
i was also thinking about um you know
the customer tracking uh notifications
so um it's not just the the order
tracking but it's like how do i keep the
customer completely updated on the life
cycle of like the t-shirt being produced
and everything else
so
this is kind of like the the default way
that i work
and it's very different to what was
actually needed for the project and
because it was a weekend project i kind
of made that final call to escape
dreamland
so get my head out of the the clouds in
the sky and just simply focus on what
was actually needed to be delivered
and it takes a lot of energy and
patience for me to do that
and uh and we got there eventually right
so i just really needed to get started
so yeah i went back to my favorite tools
as i mentioned beforehand python and
flask and i started to work to build the
app over the weekend
so easy done and dusted i've made what i
designed very simple it all works
end to end very very nicely
you know like it was just one simple
event one simple use case i can
basically park it now
but no
that didn't happen in the end about two
months later i had a couple of new
people other friends that wanted to
leverage this um solution from me as
well um they reached out and the
original friend she wanted uh to use it
for another event as well so i guess
what that meant was that i needed to
make a few changes
and this is kind of like the purpose of
the talk as well right like if i'd if
i'd over complicated things and built
what i thought was needed at the very
start the app would be very different to
what it is today and i'll show you the
differences at the very end
but i wanted to talk to some of the
complexities of um of the solution that
i built as well so you can kind of see
the the journey that i went on and the
complexities and how i kind of came out
the other end with quite a different
architecture and quite a different
application than i thought and that's
just all built through that muscle of
experience so i'm really happy that i i
started with a basic concept and then i
basically added and iterated through
that at each stage that um something
needed to happen and the project needed
to grow or the app needed to grow as
well
so the new request that came in was they
had a couple of new items very similar
to t-shirts i think they were track suit
pants
uh by memory so my friend she wanted to
have track suit pants this time around
the other thing was uh
the other friend that came to me two
months later as well so this is two
people
she wanted to use it for different
orders so she she was
she had a different vendor and
a slightly different thing i think it
was a hoodie if i remember correctly
but she wasn't going to use that same
vendor and what that effectively meant
was
rather than having like a list emailed
to one vendor i now had multiple vendors
that i had to bring in and support with
my application
but those vendors also had different
ways of working like the first one was
very very flexible and could just send
on demand
you know just in time delivery i guess
the other one
was really focused on having like a full
list of all the orders that were needed
for all the customers and like at a
certain time in the uh before the event
um
that company would then ship everything
all at once and so they kind of wanted
everything presented in line items
so that kind of got me thinking about
the architecture again
and i kind of realized in some cases
i am actually going to have to introduce
a database um
and think about the security and privacy
of this as well i don't really like
handling usernames addresses
phone numbers and all of that
um so you know i was very careful on
what i thought about in the security and
privacy realm of things
but but introducing this database as
well um you know i i ended up creating
like i think an events table um to
manage like the couple of events that
were coming in but i was still manually
like almost like creating a
a
like a
every single event like i was starting
to as more ass came in i had this like
structured um
like event
uh item type
is how i'd refer to it so it's like um
you know this event has t-shirts um
t-shirts have sizings and they have
types
but um
you know like uh hoodies
uh might be uh unisex so you don't
really need to know the type it's all
gonna be the one um but it still needs
the item size and so that kind of like
made me think a little bit more about do
i need more flexibility should i be
using sql or should i
move across to nosql
because i can have things as like a json
string and maybe an object and i don't
have to it means that i'll be more
flexible if we start offering more than
t-shirts so it's kind of like my thought
process here um and i'm really happy
that i did that in the end
because new items and more vendors came
so we had uh we had breakfast getting
delivered um was one of the use cases my
friends said they wanted to send um you
know a bunch of friends for a particular
event uh breakfast on the house and we
have breakfast delivered across
melbourne using the application which is
really
cool
we had those hoodie cases we had
t-shirts as well we had socks we had
i couldn't find a emoji for rubik's cube
maybe that will come sunday down in the
future so i've got an ice cube here but
we were like sending off rubik's cubes
and pins and just a whole bunch of other
stuff
and so if i go back one i'm really happy
that i chose to go the nosql route
you know it would have been perfectly
fine for sql there's ways of working
this into sql
but you know like this is a project in
my side time and it was really good to
just have a json object that i could
interpret and uh
and show the different elements that
customers might need to put to the order
list so kind of made my life a little
bit simpler for the side project which
is yeah which is really good
i ended up creating that vendor table
because i realized we've got multiple
vendors here and i had that flexible
solution of like
using the database versus just sending
an email depending on like um the
preference of the vendor i had that
design in the table as well
the other thing that i had to start
thinking about was like the event hooks
right like um when when does the event
close when should i send the order data
to the vendor
and the customers like when am i going
to clear the data out because i don't
really like to store this type of
information long term right so i want i
want it all gone once the event's gone
but you also need a little bit
you need to keep it for a little bit of
time as well because sometimes customers
need to change the order uh sometimes
the
vendor might lose the order as well so i
had to think about timing around all
these things um also which was quite
interesting so you can see i'm like
learning a lot from
what i originally thought the ultimate
version of this could be um it's kind of
it's already branched off to something
that's a bit more unexpected as i kind
of get domain uh knowledge of how these
things work
and then the other thing was um i was
still updating a lot of code for each of
the different events so every time a new
event needed to be created
i would be like creating a route for
that event so you could have slash the
event name
i was
i was kind of like rebuilding the
application as well redeploying the
application so you know there was a bit
of manual love that i needed to do there
in some events they wanted
a quick image hosted or they wanted a
detailed description versus no
description no images
they might have wanted different colors
in the background and all of that so
things were kind of changing quite
rapidly
the next thing was that that kind of
took me into branding and allowing
others to manage events because this was
a hobby project uh this was just a side
project and this was for fun and this is
to help a whole bunch of friends so that
suddenly needed use cases for this as
well so they could send things
everywhere
and so i i started to think maybe it's
time that i have
a administration portal or a form
builder and and those things are
complicated beasts i tell you
um
you know i i i wanted to not have to um
manually change the code with the routes
each time so i started to try and like
clone the app
and have it deploy with a subdomain to
make my life easier so i looked at some
of the cloud solutions in that space
to make things quite easy for me where
like if i um if i simply made a request
i could set up a new subdomain and and
have the app deploy and then have the
data that's relevant to that particular
program
um
some of my friends wanted codes as well
so if anyone found that page like it
could be a unique code that was entered
to say hey i am part of this event so
they didn't want authentication as such
but like um this redemption code that
could be used so i ended up having like
a code table
to manage this as well
um you know on the admin portal and the
form builder side i needed some
authentication i needed the people that
were building the events that i'd say go
yeah create your event here they'd have
to log in and i wanted them to be
managed it was too i didn't really want
to do this for end users uh because i
thought authentication is a bit heavy
like no one's really going to use my app
twice right like they're just going to
go to a particular event put in their
details and then you know have a product
shipped to them so i didn't really put
authentication on the end user side but
i thought you know my my main fringe
she's been using it multiple times i've
got other friends that want to use it
like multiple times that's where i kind
of started to look at that admin portal
the form builder was a real headache
actually i ended up like having a little
bit of react here but most of it was
made in python and um what i essentially
was doing was like i was uh i was saving
to the database this adjacent object
like so they could add remove fields
and then like if you become a point
where um you know they've built exactly
what they want
and that will save the json and the
database and then um what i can have is
i can have my application deploy and um
and i can have those fields shown for
that particular event um you know based
on what they've built out so that was
really complicated to work for that took
me a couple of weeks to to kind of like
look at and find a solution there and
leverage a couple of different open
source things if i remember correctly
um and then the other thing was i wanted
more automated deployments so i'd
started to look into like when i submit
code um could i have multiple branches
could i have that enacted ci cd to do
the builds can i have some
some level of control over um doing the
builds issuing like ssl certificates for
each of the different urls creating like
the urls and the routes the urls and all
of that
so i kind of got into the deep end with
all this stuff uh the last thing was uh
rather than having everything served
through the flask web application
including images and stuff i started to
think about moving it to like object
storage or hosting so i looked at my my
uh the cloud solutions around that
and i started to host the images there
because that kind of took a little bit
of the headache around uploading off of
my hands and somebody else could worry
about that if anyone's done like uh you
know image hosting or this and that um
you know it's it's a very it's a very
big pain to implement securely so i
usually pass it on to the hosting
provider to have some kind of hosting
you know object storage solution there
now
i'm just gonna make sure i'm on time yep
perfect
now the next thing was the cost was
erratic right like i would have the
server that was running all the time or
set of servers and like i'd have them
running for the whole event but i might
only get like a couple of hundred to a
couple of thousand orders over a period
of like a month um leading up to each of
these events before the merch was sent
and um you know i was paying out of my
own personal pocket for this this was
all for friends and you know got it it
got very um expensive having multiple
servers um you know mocked up and
running for about
um a month each and you know my cloud
bill was going up to about you know a
couple hundred bucks which is not ideal
when it's out of my pocket and so it
kind of got me rethinking like what am i
going to do here right like
am i going to
am i going to have a look at like having
a containerized solution um and having
very small
containers launch and then like i'm
scaling them up if i need to i couldn't
really work out a way of effectively um
pausing these containers um
like one of the challenges that i had in
the space was like um
i don't want the user to have to wait
for a server to relaunch for you know a
minute before the url loads for them if
if like i haven't had much activity for
like four or five
hours on the ordering system
um and it was still
cost with all the different services
that are all the different servers that
i was spitting up so that kind of led me
down the serverless route and i thought
serverless is actually a pretty good
solution for this application um
serverless solutions are kind of
ephemeral like they launch very quickly
um they do a particular task and then
they kind of go back to sleep until
somebody comes back right so i thought
well what i could do is i could use a
a cdn a content delivery network i could
have my images stored
within my object storage my object
hosting and then what i could do is i
could just write
small snippets of code to basically like
enact what i want to do with the data
and check what's in the database and
send notifications and this and that
and so i felt like it was a pretty good
fit for serverless plus i wanted to play
with it to be honest as well and learn a
bit more
i say flask serverless here
it wasn't actually flask i used
something very similar i found a
framework in particular
that was built for a particular cloud
vendor so i i ended up using that
solution um
and that worked really really nicely for
me uh it meant that i could tie into
like their object storage quite easily
the database storage quite easily with
minimal work and to kind of move from
like that existing um flask application
to floss uh to the serverless
application it was actually kind of
minimal effort right like because i
basically just copy pasted the routes
and set up separate files and
kind of separated things a little bit
and reworked a little bit of the uh the
logic it was a lot quicker than i'd
thought
um i'd probably i'd probably go down the
container route if i had something
really heavy that was always accessed um
just in case anyone's wondering um so i
always found that interesting too um you
know like there's always a point where
it's like is this a serverless use case
is this a containers use case or should
i keep my like existing app running as
is and deploy you know like it didn't
one go as one thing um which i might do
if you know if i uh if i need to
maintain state and i've kind of baked it
into my app for some silly reason
sometimes you know it happens
um so i went down that route and the
other thing was like i had a couple of
users kind of say that they they had uh
lost their order or they
um or they don't think the form worked
for whatever reason uh and so i kind of
started to think i might need to do some
logging here um i might want to have
like some alarming like based on certain
events as well i might want some alarms
set up if the bill starts getting too
expensive and i haven't realized i've
done something in particular and that's
eating up cost
but most of the alarm was there to make
sure that like um things were scaling up
and things were deploying and things
were working as expected and then i also
like just for fun because i wanted to
learn as well um but i also wanted like
um
to not just like deploy the app each
time in ci cd i wanted to kind of create
these as like many many little
applications so they talk to the same
central database they'd be storing
things in the same bucket um but i
started to think about how do i create
like a whole bunch of like
infrastructure around um so that i could
recreate the whole environment through
code um very very quickly so i looked at
like some of the tools in that space
which is really cool too
i also started to and
this is like something that was was in
the works and i actually hadn't finished
off because i haven't used uh the
application for a little while now but i
started to think about like not just
having like email as a notification
service um from my cloud provider i was
using like a tool that they had for that
there
um
i started to think about like do i
introduce sms as well and that might
help with um the customer
you know in these bulk orders where they
might submit at the very start of the
month the order doesn't get processed to
the end of the month at least they can
see their journey um with that with that
vendor it's like hey
if the vendor's able to expose like
updates on my side i could translate
them was what i was thinking and i could
basically have
let's say
let's say uh the order is starting to
get processed the order is now in
manufacturing the order has been shipped
and then you get shipping updates until
it arrives at your doorstep so i kind of
thought that would be a really cool
experience and sms doesn't cost that
much as well um so it wouldn't be free
but i thought that would just like make
the app more friendly for end users to
use even though i'm running it out of my
own pocket
um so that's that's kind of like where
we ended up right um
and this is kind of where we are today
so i wanted to kind of do a comparation
right like if i'd started with my
perfect architecture my perfect
application the perfect way of building
things based on my head i wasn't really
a domain level expert in the space
i would have ended up with a very
different um you know product at the end
of the day so i wouldn't have i wouldn't
have realized like i needed more
flexibility in my tables i wouldn't i
would have realized that i probably
didn't actually need to use redis
because i wasn't really maintaining like
authentication or state from end users
um i was simply just like creating the
order and then having things handled
from there um you know i wanted to to
kind of go down the container route but
i realized that serverless was going to
be cheaper for this use case
you can see how different the two
solutions are when you kind of compare
the really basic architectural diagrams
that i've got here
so this this kind of comes to i guess my
learnings and the summary itself um
so you know
essentially like just a recap for
everyone it was a weekend hobby project
um i could have massively over
complicated you just as you just saw
projects kind of i guess this is
probably the key learning that i had or
the key thing in summary is projects
take on their own life um as they get
used in real life
and so it kind of made me second think
about trying to lock things in
at the end of the day and kind of
setting out this is exactly what the
app's going to be this is how it's going
to grow up like this is how i'm going to
productionize things
because i think all of that stuff adds
adds weight to me getting started right
like i i have to
i have to think about all these things
and then there's so much complexity and
it's so overwhelming it kind of delays
you getting started but it also can
delay like once you've gotten started
like you being able to deliver something
very quick and valuable for end users
that's actually going to get used and
you're going to get feedback from right
now as you can see i kind of use some of
my own photos
in the deck but i've tried to use emojis
for the rest just because i like to
fully own everything that i've i've
built here
so you can see it's a recycle pattern
but my additional learnings and it's
really supposed to be like an
evolutionary loop right so it's it's
like things things have a life cycle um
you have a development life cycle you
have a feature
life cycle you have a life cycle as you
work through bugs
and i guess like i've just really
learned to not over engineer or over
architect or over design things at the
start kind of just let them breathe as
i've said beforehand
um you know the app is ever changing and
growing it's never finished it's okay
you know design or architect for what's
exactly needed at the time and what
people are asking for don't don't try
and over engineer everything from the
start again so kind of the same point
and the other thing is like refactoring
is like good right like it's it's really
nice to rework over the code that i've
got and see it grow and um and see that
growth um at the different application
stages you know like i can go back and i
can
see the original code that i had versus
where it ended up and it's kind of
really satisfying to see that growth
over time too so it's just a nice little
thing that i found
so this is it
i just wanted to kind of take you
through one of the journeys that i'd had
and shared some of the learnings that i
discovered within that journey i hope
this was valuable uh to uh to people um
hopefully it kind of gets you second
thinking um you know about making things
too complex to get started with just
design for exactly what you need
i think it's really um it's really uh it
kind of it really helps me
kind of just get through that initial
hump of like this is so such a complex
beast it's going to take me forever and
actually get me hands on the tools and
started to build so that's kind of
that's kind of my main learning so
thanks everyone for for watching i can
hover around for questions but i might
pass back to you justin
well we we have a few questions that
have popped up through the chat so um we
and we have a bit of time now so uh
let's let's ask and answer a few of them
if if that's okay with you
yeah let's go for it awesome um so i'm
gonna cherry pick one in particular
which came in later but how many hours
went into this alleged side project
yeah so i mean it was over a weekend to
start right so we're talking about six
or seven hours uh to do the base level
and then i think it's turned into
200 hours maybe more
so it's a part-time job now
yeah basically yeah it's a side it's a
it's an after hours project that just
like gets uh iterated on uh now and then
yep
right
uh another question um is did you make
the the architecture diagrams as you
were going or is this something that
you've done in developing the talk
yeah so i did the architecture diagrams
in the talk um so i built them just via
powerpoint
the reason kind of why i do that is
because they're actually usually just
sketches in my notebook right and they
i'm not very good at sketching so
um i needed to clean up a lot of the
stuff and the other thing is i'm not too
worried about like having a diagram as i
produce things right i just want to get
in there and build so i need to
understand what the use cases
document the use case in my notes
um and then kind of like think about and
explore solutions for that use case and
and that's kind of what i've walked
through today so i actually never really
produce architecture diagrams until i
need to
walk someone else through something
right
right so did you like sketch them on on
a pad as you were working it out or is
it really the architecture just kind of
emerged as you were building it and then
you've made it pretty now yeah it's it's
it's bits and pieces right so um you
know like i just put it in my notebook
and if i need to sketch something out
and document it then i can look at it
later and go yeah what am i going to do
about this database okay
um i'll try to order these with that um
is there any reason why you didn't
consider django once you realized you
needed an admin portal and forms and all
that sort of stuff
yeah good point i had thought about
django um
i just like the freedom of working in
flask i think it's just a personal
preference
um i i like to know what's happening
behind the scenes um
django is an awesome framework uh and i
kind of i guess i didn't expect it to
grow the way that it did right uh
i didn't really expect i'd ever need an
admin portal like to be honest and so i
i could have redesigned things for
django but i thought i'll start simply
just by building something with fast
because i can do that in the weekends
right um and last question uh because
we're running up against time um uh last
question for here but there'll be more
in the in the chat if people want to do
that so do hang out there and and
everyone else do ask more questions in
the chat or in the hallway track
um what's involved in deploying flask to
a server environment
ah yeah um so there's complexity in that
uh
to to kind of be exact i was using
elastic bean stalk
um i could have used like a product like
light sale or something like that if i
wanted to as well
um so basically like the the advantage
to using a solution like that is i can
go this is my code repository that i've
loaded in from github uh these are the
scripts that i need to run on the server
to do the deploy i'm using uh you know
uh gunnacorn or g unicorn someone's
gonna pull me up on that
to do the deployment um so i i kind of
i kind of go like github to one of these
really easy to use frameworks
right
well with that um we're up against time
so i will i will leave it there but i'm
sure people will have other things that
they they want to ask you about so do
come and hang out in the chat uh for
everyone else um we have a break now uh
until let me check my notes until 4
if i've got the check on that correctly
yes that's right so until 4 15 pm so
you've got about a 45 minute break uh
good time to stretch your legs get away
from the screen a bit drink some water
you know practice a bit of that
self-care
and we'll see you back here uh same
place same that time same bat channel at
4 15 p.m for a talk by uh whoops hang on
i pressed the wrong key molly
rowe
molly rowe called metrics for good and
not for evil
which i am particularly interested in i
love love me some metrics and uh you
preferably for good not for evil so
we'll see you back here in about 45
minutes uh otherwise hang out in the
chat and we'll continue talking all
things devops see you soon