>> Hey, friends.
One of the best ways to learn Azure is to use it.
However, you don't want to break the bank.
It's also helpful to create something useful.
My friend Frank Boucher built
a budget friendly URL shortener
that you can deploy directly from GitHub,
explore it in Azure,
and customize it for your own use,
and I'm learning all about it today on Azure Friday.
[MUSIC]
>> Hey, friends, I'm Scott Hanselman and it's Azure Friday,
and I'm here with Frank Boucher who
has got something budget friendly for me.
He knows that I don't like to spend
a lot of money when I put my things in the Cloud.
What have you built for us, sir?
>> I build a URL shortener.
I do a lot of videos and I thought
a URL shortener will be useful because nobody
remembers a very long URL or something random,
and I thought since everybody
these days are doing more stuff from home,
I thought, making it easy to deploy will be also very interesting.
>> That's cool because there are
little URL shorteners out there like Bitly and this and that.
But I don't own that domain.
I don't know if that's going to go away some day.
With this shortener, it's basically owned by
you from the domain all the way
to the storage like you own every bit of it.
>> Exactly.
>> Very cool. So let's see it, show me how this works.
>> So it's all in GitHub.
So the name is AzUrlShortener,
and I built that streaming,
so all the steps of how it
was built is still available online on videos,
and to get it, you just need to click that blue button here.
So if I control click to open it in a new tab,
will just open and now I've just a few questions.
So in our resource group,
so I could create something cool like to
delete and then you pick your location.
I give it a base name to make sure
the resource you are creating are never used,
it will add a suffix automatically for you.
Then a thing I like about that,
and I did that recently is you could decide
it to go headless, no front-end.
So you could call it directly from an API
using Postmen or any tool you want,
or you could use the Blazor website that I did.
I've instruction to help people if they wanted to
build their own front-end and add it to the project.
>> So you can use it as an API or have an optional front-end.
>> Yeah.
>> Cool.
>> Then you decide the URL you want by default.
Could be your blog, your website, whatever you want.
Then because I'm using that deploy to Azure button,
I need to have the GitHub URL.
So if you decide to change a few little things,
you could forward the project,
and then you need to change this thing.
Otherwise, if you do it straight from my GitHub,
you don't need to change anything.
Here those two expire on and owner name,
that's a value that I use and I create tags.
For me it's just a way to make my subscription efficient.
So every Monday, I run the script
that analyze and everything that has expired on,
and here I'm doing air quotes, but nothing will happen,
but it will give me a report saying these resources,
you should maybe check and
delete them if you want to keep things typed.
So always use those things.
For the front-end, if you're using a front-end,
then I will need a username and a password
because I don't want everybody to create short URL on my account.
So you just fill that.
It run for like five minutes,
maybe less, and then you end up with a bunch of resources.
>> Okay. So when I first see this though,
I see a lot of resources and I might be worried that like,
"Oh, if there's a lot of resources,
this must cost me a lot of money."
What are these resources and what do they do?
Which ones are free or cheap?
>> Well, everything is cheap. Right now the most expensive one,
and that's on me, like if you deploy that from my GitHub,
you will have a cheaper version of me,
just I'm doing a bunch of experimentation.
So this one like that's the website right now,
I boosted it a little bit to do more tests and being [inaudible].
Yeah, and when you deploy,
I usually put you in the free tier.
So it's free and it's cheap.
>> Great. I like free.
>> I put it something heavier just to seek,
what if a worst-case budget mindset.
So storage, here the two last in the bottom,
that's super efficient for pricing and I use one for
the storage of the data
and the other one is for the Azure Function.
After I have my plan,
this is the little purple bulb, that's Application Insights.
That's a free service,
and right now, I'm not leveraging that in the application.
That's under the stack of to-dos.
It gets a lot of the information about your URL shortener,
like when people are clicking on it,
like what's the performance and stuff like that,
so we'll leverage that in the future,
right now, I don't have anything.
Well, you still can access it through the portal though,
and then Azure Functions.
So Azure Function is fantastic because you're built by a second.
So when you create a function,
when you call the API,
so create me a short URL with this thing,
it only runs for a second,
maybe a few milliseconds.
So you just get charged for that and you got bonus,
you got a lot of free calls anyway by month.
So I've been running that like this is
a new instance I created this morning because I was streaming,
but my personal instance I've been running a month now with it,
and it's less than two dollars,
Canadian dollars, so it's very cheap in US dollars.
So and those three top resources are for the website optional,
and by default like I said,
you will go in a free tier,
so it's very low expense.
I push the expense a little bit just to
see like what if I go and add more stuff in it,
like what it would look like.
In this case, I think I'm still under five dollars a month.
>> That's a really good thing to think about
because just because I
see a lot of resources and my first reaction is like,
"Oh, this is going to be expensive."
What you're really showing me are a lot of
free resources that are born on
the Cloud native resources that make
this application simpler than just a website.
>> So yes, it is just a lot of resources,
but very small resources,
kind of microservices architecture.
>> Exactly. Those small service architecture
is made for an application that can scale.
Do you think that even though it's budget friendly,
that like a million people could use this tomorrow all at once?
>> The Azure Function will scale automatically.
That's the beauty of them.
You focus on your code and everything else is not magic.
You could control it if you want,
but yeah, of course it will work.
>> That's cool.
Can we take a look at the code and
you can explain to me how this works?
Let's switch over to your machine.
>> Great. So you can see my code now.
So this is right like the GitHub contain everything.
But right now I'm in the Azure Function that
generate or create the short version of your URL.
So I'm expecting a post
and you send the long URL and I give you the option,
you can send me what I call the VNET.
You can call that the end of the URL if it makes sense for you,
and if you want,
I will use that, if you don't,
I will generate one for you.
I just create a response and return you that.
What I do is, I just create that token if I
don't have it and save that in
Azure Storage Table, very, very basic.
>> So right there where say of short URL entity exist online 54.
You're basically making a call to storage and saying,
has this been used before?
>> Exactly. I created a little helper here,
if we go I just run.
>> It's very simple. You just say there's a table,
does the thing exists, the row exist?
>> Yeah.
>> You're using the Azure SDK just directly?
>> I'm using the Cosmos Table SDK.
That's the best SDK that I found right now,
and it's very,very simple to use.
So it's always the same kind of
[inaudible] where you do a select or
an update or delete if you want.
>> Okay.
That looks really clean. So then when you go back over to your.
>> The function.
>>The function, and you go and you say, "All right,
that's cool, " then you can say there's
a conflict because I already have that.
Otherwise you go and create it then you give back the new URL.
>> Yes. So I checked if it doesn't exist.
If it doesn't, I create the record,
if you want to say the entity and I will save
it and return the result to the end-user,
and it's a JSON object.
>> Your Cosmos Table is really just two columns.
>> It's not a Cosmos Table,
it's a storage table.
I'm using the Cosmos SDK.
>> That's a really important thing for me to understand.
So you're using the Cosmos SDK because you
like the way it feels and the way it works.
But you're not talking to Cosmos,
you're talking to storage and storage has two columns.
>> Yes, I save a little bit more information.
I keep the date that I create.
So you have the partition key.
So the partition if we go technical,
it's the vanity, the first letter is used for the partitions.
So I find out
equally the URL in the long version, that's it I think.
Now, the short version also now.
Yeah, it's true. I added that recently.
>> Finding out makes sense when we talk to
people who are using anything of scale.
Having that partition key is so important,
even though we're just partitioning
on either 26 letters in the alphabet,
or if it starts with a number then out to 10 numbers.
Just having 36 partition keys will make
a huge difference if you had billions of these in your database.
>> Yeah. So very simple,
and then when you click, right now,
I keep only a little bit of statistics.
For example, every time you click in the main table,
I just add plus one to the number of clicks,
and in another table,
I keep the timestamp.
So in the future, what I would like to add is some graph.
So I could see around 2:00 PM today,
a lot of people were clicking,
my blog post was working or something like that,
so you could follow that.
So you could go deeper also using Application Insight,
but I didn't implement all of that yet.
>> Okay. So this is where you make the URL,
show me where you pick up the URL
and you actually do the redirect,
and then is that under URL redirect right there?
>> Yes, it's in the UrlRedirect,
and that function is called by default,
I'm using the Azure Function proxy
because when you call a function in that function app,
you need to go function app API bla.
So we don't want people to remember that.
So I use the Azure proxy,
if you don't parse not like if you parse nothing,
I will redirect you to this function doing the mapping for you.
>> Then there is your Azure do a 302 redirect?
>> Yeah. If I found it,
I just create a response and do the redirect.
>> I feel like I need this,
I need my own Hanselman URL shortener.
So can you show me your GitHub again so
folks can know where they can get this setup for themselves?
>> Yes, of course.
I could do better than that,
I could do something like this.
So for Cloud five-minute CA because I'm Canadian
and project because it's the project of the URL shortener.
>> So folks can check that out at github.com/fboucher,
or they can see c5m.ca/project and they can also check you out
streaming on the regular and exploring
code and building things like this for us to see.
>> Exactly. If they want,
they could even add their own front-end.
>> All right. We have been talking with Frank Boucher and
it's been another episode of Azure Friday.
Hey, thanks for watching this episode of Azure Friday.
Now, I need you to like it, comment on it,
tell your friends, retweet it.
Watch more Azure Friday.
[MUSIC]