Welcome to this session of building
Serverless apps using azure cosmos db and azure
Functions. So let's go quickly on the
Agenda. I will be briefly talking about
What is azure functions, how you can double up it.
And then we can see how we can mix two together and build real applications.
And the last one is write some code to solve a real business problem.
And then we have customer stories. We have two customers here with
Us. And they will be talking about
How they are harnessing the power of azure cosmos db and
Azure functions and solving a real business problem. So it's not going to be all
Theory and just talking about some code, but we will see how
These functions are put together to solve real business problems.
And in the end, we will leave some time for questions
And answers.
Hopefully, we can answer most of your questions here.
So, as you -- most of you must have already seen the slide
Where we gain in productivity as we keep going more and more
Inside the cloud, as we move from
Infrastructure as a service, we gain in productivity
And we stop working about other stuff like where is
And things like that. So the more you go inside the
Cloud, you gain in productivity. So benefit of serverless, here
We manage apps, not service. In fact, not even apps.
We manage just the functions. So we just write the function
And you don't worry where it's deployed and how it will be subs
-- But you can start with a
Function and deploy. And it's as simple as that.
Now, once you are away from
Software and hardware and patches and updates, you get
Into big savings. And because of these two
Benefits, you get faster time to market. I think you guys must have heard
This many times. This is a wonderful time to be
In technology and be a developer. And it's really -- it's amazing,
Especially for old people like me who were in this industry for
-- I don't know how many people. But today from your conception,
Like you thought about something, and you can have it
Deployed and working in production. But that time has shrunk because
Of this technology of cloud and functions. Like you can think about
Something and you can have a product i've done in a few hours.
And one of the apps i will be showing you, maybe i'll talk
More about it when i show you that that app in '90, '92 when i
Built it took months, and today we can do it in a few days.
So it's really faster time to market
In true sense. And because of the ease of these
Azure functions, all are possible. We all know the benefit of these
Micro services that you can have. They're independent.
You can develop them and scale out independently.
So all this is possible because of azure functions.
So, functions. What is functions?
So, the definition of function is it's a self-sustained code
Which solves a business problem. So that is that your function
Now, as we all know, that function can have other functions and all that.
But when i say that, i mean you have a service which is solving
One of your business problems. You can develop them locally and
Then deploy them on the cloud. You can debug also locally.
You can just write a few lines of code and then see that as we
Go along, that how easy and simple it is.
And functions, this is the productivity. We will talk more about them.
And you can choose a variety of programming.
You can choose any of the languages to write functions.
And it can --
In this slide, i'm showing this today. One thing you will note, there's
1 X and 2 x. There are two versions of
Functions. 1X is already in public.
And 2a is available soon. The difference between 1 and 2
Is 2 is addressing the .Net code market.
You can trigger a function because of those services can
Trigger a function because of some activity happening there.
And then we have input and output binding.
That's defining input and output on the functions.
So we will see another example of how easy it makes to write
Code, connecting to all these different services.
Yesterday when i was writing the slide, the previous one, and
Suddenly something came in my mind, that this session, this
Video is recorded. And it will be put on channel 9
After like 24 to 48 hours. And the reason is, once it's
Finished, they'll take this video and put it in a queue
Where we have all these hundreds of videos going to the process,
And then they can put it on the website.
And a few years back, i was thinking, we have these hundreds
Of thousands of computers in microsoft.
On every dev desk, we have one or two or three computer.
And they are all sleeping at night, doing nothing.
And you have all these computers can which are just sleeping and
Doing nothing. And i was thinking how i can use
This computer at night to do something. This machine may not be
Sleeping. And a few years back, it was
Really difficult to do things like that because you have to
Have this whole orchestration engine and how you write the
Task and who will pick it up and all those things.
Now because of these paradigm of
Azure functions, serverless code, all these machines you
Have, they can be having some azure functions running in
There, listening to some queue for the work and they will work.
I thought this was something interesting.
I should just bring it up and i'm sure you'll come up with a
Lot of different use cases. All of these machines which are
Sleeping at night can start doing some work.
So let's build some functions and see how easy
We can write them.
They say in every demo something will go wrong, and today my
Mouse went off. So i have just the
Dos window opened. I already installed my azure
Functions run type. So to write the function, i
Would say func new.
And as you can see, we have option of many languages here.
So here i just choose c shop and then i can see all these options
Are there for me to write azure functions and there's a
Template. It's all ready to go.
So we'll just choose this to build the parameters.
And i give the name. Azure functions 7.
And that's it. Now let's go and make sure my
Ct-host is running. Now let's go and test it.
Okay, from my -- oh, sorry. Isn't it 7?
>> You need to change the name in the function.
>>Mm, af 7. So when i look at here
, So this is the
Api, af 5. Okay. Af 5.
So this is the function i wrote. Let me
Just quickly open it in
Ct-code.
So this function is created by
Just writing that function new. And you can see the code is here
And you can start writing yourself whatever code you want
To write. Now, as i said, there are
Multiple ways to create the function. Now let's quickly look at -- so
We can just go on the portal and write a function there.
And i want to come here to the portal
Portal. So i already opened this
Beforehand, before the presentation, but somehow it got
Closed. Now to create a function in the
Portal, it just created a
Source. And that's why i tried to open
It before, because it takes some time and everybody waiting on this.
Not a good idea. So here we can start writing functions.
But before that, we have to create a
-- So all these functions, they are
Hosted inside an app. So function app.
Sorry. I should have
Typed functions. Okay, function app.
While i'm trying to show you this, because there are a couple
Of points. We should bring it up.
Function app. Then you say "create."
As you can see, this screen is asking you very few things.
You just put your function app name.
And then the subscription which you already have.
And then you have an option to have os.
You can choose linux or windows. So here's everything you have to
Think about. It will be just charged for
Whatever resource. And if you want to have more
Control on your function app, then you can host it into the
App service plan. There are other -- a couple of
Subtle differences are there. These function apps will sleep
After five minutes if there's no activity.
You can create it with ten minutes with the configuration.
And if there's a trigger happen, you have to wake up if your
Function is running in the app service plan.
All other triggers, you have to make sure it's already make.
The system will make up your function. So that is one of the big difference.
And there are other things. If you want to really -- want to
Use your own hardware, software and things like that, then you
Can choose app service plan. And if you choose this, you can
Go ahead and then you can see there are a lot of other options
Out there for you. Sorry.
So then you say, "create new." Then you have all these pricing
Options. And each option will give you
How powerful a machine you want and how you want to deploy these
Functions. So, that's about defining your
Function application, which i would
Not do that because i already have.
And that's it. Once you say "create," it will
Create your function app. And if i go back
-- So this is the function app
Here. As you can see, there are
Functions already inside the app. And i can go and say, "create a
New function." And you can see there, these are
The options you have. It's out of the box these
Options are given to you. Interesting one i saw yesterday
Was you have saas token
Generation and then the git also. I was talking to some customer
And they were wondering, a lot of our keys, master keys and
Things like that, we put in the git app.
And if you have a big enterprise, it's very difficult
Because you're writing some test application and they have the
Key and they just check in by mistake.
Now with these as your functions, now you can write the
Git app and then you can make sure. By checking, you can go through
The key and see if there's any key there or not.
So i can just choose here one of the functions
Let's choose this. And here you can see today the
Option is c shop, but these options are increasing.
Every day we are adding more and more languages.
Authorization level is function. By that, we mean you have to
Pass a key to call that function. But otherwise, you have two
Other options, anonymous and admin.
Admin is, again, you have a host key to call the functions.
So this is it. Once i say "create," my function
Is created on the portal. So it is as simple as this.
And you can go ahead and you can test also.
So i choose git, name okay.
And here you'll see the output. So you saw the simplicity of
Creating this function and just testing it then and there.
And they will go -- in the presentation, we'll write some
Functions which is bigger than two lines.
But it just shows the point that how easy it is to write these
Functions. [Sneezes]
So we talked about azure functions.
Now we're going to talk about azure cosmos db.
So if we had the azure cosmos db collections, whatever changes
Are happening, you can see it on the change feed.
Today it is -- today it has only in certain updates.
It's coming soon. And you can work out on -- the
Delete is just putting the soft delete. And change feed is on by default.
You don't have to do anything. There you can a collection.
You can rate it. And you can rate this change
Feed from if it's distributed, you can read that change feed
From any other geo location.
And this is important if you would like to have better
Performance and then you would like to go to certain geo to
Read the change feed. You can have multiple
Applications can read the same collection.
So what are the scenarios enabled?
One is that we already talked about that.
You can have some function listening to all
The changes happening in cosmos db and you
Can do certain things on it. And you can send a notification
To notification hub. Basically i feel once you get
The change feed in the azure functions, sky is the limit.
It's all your imagination what all you can do.
And number two is you can do some real-time
Analytics using spark and all that.
Today in cosmos db, we don't have aggregation because it is a
Distributed database and doing a good-bye across a thousand
Partitions, billions of rows can be very, very expensive.
So you can connect spark. And as it's coming in stream,
You can do the processing on that. I don't know if there's a
Session on that, but there are youtube videos on cosmos db and
Spark. You can see how we can enable
That scenario. And then you can move some data
To cold storage. Move the data to storage blob or
Other cosmos db functions.
We already talked about micro services. This is another way we can
Enable micro services. So when i'm listening, as soon
As i get an order, i can kick start my shipping service, tax
Calculation, and payment. All these things can be enabled
By change feed. And i think we're going to here
From other customer how we are using it in the real-time, in
The real business scenario. Next is this creating a micro view.
So all the data is coming in, and as you already must have
Heard or seen, kos -- cosmos db is --
In that kind of throughput, you put it back into the cosmos db
And have your application look at the data coming in and the
Abbreviated data also. So that's another way.
We talked about replicating the data, moving the data to cold
Storage for long-term keeping. Now let's see how we can read
Change feed. There are three different ways
To read change feed, and each of them have their benefit pros and cons.
And i will quickly go through all these three options and show
Ct-you some code. So the first option was to have
Using the document client library.
Using that, you can read the change feed.
And here in the code, there's a lot of boilerplate coders there,
But what we have to really pay attention to is in this line,
You just go and find out what
Are the partitions are there into the collection.
So this way you will get the
List of all the partitions, put them in a partition key range.
It's just a list you just want to have because you are using
The client library because you want to have a lot of control,
That you want to read exactly this partition of the data.
And that's why we come down to this level, which i would say is
A very deep level, and slowly keep going above.
And then you will see how easy and simple it starts becoming.
And then here there's some change feed options.
As you've seen before, you've got to the partition key range
Id. You set that.
And then you have other option. You say, "no, i want to read the
Change feed." So you can get all the data,
Whatever has changed or you can have the continuation token and
Then you say, "i just want to read from here."
Because when you're reading to get token, and then you can save
It and use it later to read the change feed from a certain place
In the feed. And we are saying how many items
You want to read at a time. And then you can put the start
Time and you can go back. So you have all the power, all
The change feed to go back and to and fro to get this data
Coming to you. And that's it.
And after that, once you call this method on the query, you
Will start getting the data into this read response, which i am
Just displaying here. Don't worry about all this code.
All this code will develop to you and
Github. And i will share the link with
You all later. I didn't talk about client.
Client is document client which you are
Ct-creating from here. So, let's run it.
It's waiting and listening for changes, this app which we have just written.
Ct-and i'm going to put some data into the collection.
Ct-let me restart this thing.
Okay, finally.
So we can see the data is coming in and this is as simple as this
To write how to listen to change feed. Now i want to go and quickly
Look at the second way where -- how to read the change feed.
The second way is to use the processer library.
That's library we wrote. So we abstracted away all this
Detail from you that how many partitions are there, the change
Feed token, things like that. And if you will use that
Library, you will use this observer token where you will
Just write your one object which will implement this i change
Feed observer. And this in this interface, you
Will just implement process change.
And that's about it. And all the change feed will
Start coming in here. But it does not mean that if you
Lose this library, you lose the control.
You have option for token and things like that.
But we simplified this very much. So you will just implement that
Interface and just there's one method you have to define to
Start reading the change feed. So this is the
Simplest way. Now i want to write a new
Function using visual studio and you will see again how easy it is.
But before that, i want to talk about the scenario which we are
Discussing in the solution. So this is the scenario.
I have all of them running. And the feed is directly coming
In to the cosmos db.
And then we are listening on the change feed using the azure
Functions. And if there's an accident
Happen, we will know within a minute to have the information
Come to us and azure functions is watching for the accident,
And then it can activate all different services.
You can send the notification to the web page, which is
Somebody's watching in a control room, looking at the map of the
City and see where exactly it is and you can activate other
Services like hospitals and fire and all of the ambulance.
So this is the project i'm talking about.
In '90, '90 i was working in kuwait and we build the same
Thing for them. '92, I don't know how many of
You remember. We didn't have any very smartphones.
We had big black nokia phone. There's no even gps.
So we put the gps on police cars. We basically drilled a hole and
Put the gps and brought the wire and connected it to the nokia
Phone and we modified their operating system.
So nokia did this for us. And from there, using their
Latitude and longitude to the sms, we send the message to our
Control room where we started the message, and then use the
Sun system on their graph on the map, we showed where the police
Car is at the moment. That was a multi-million dollar
Project and so many companies involved and nokia has to modify
Their phone and all that. And this whole thing today i did
In a couple of days, everything working. And we will see how you can even
Have the full solution working in a very short time.
So let's go and look at the code for this.
Let me close these guys before i leave.
So we're just reading the change feed which we
Inserted before. And i am showing here the
Partition id and the token which you can use to move up and down
And read wherever you want. So here is the desktop
Application where i'm looking at the map and waiting to see if
There's any alert happens. Now let's go and quickly write
This function. So if you are using visual
Studio a lot of things are done for you. Here you just go ahead and
Choose azure function. And i'll just leave it as
Default, function app 4. Leave this everything as default.
We'll come back to it.
Right-click and say, "add
New items."
And choose azure functions. And here again, we have all
Those options. We are going to choose cosmos db
Trigger. So, as you can see, this is
Boilerplate code ready to connect to your cosmos db change feed.
You just fill out your information and you can have the
Whole solution. So what we're going to do this
Here is i have this code which i am going to copy and bring it
Here so you don't have to wait and see me typing everything.
So what i'm doing here is in
Read-only list documents, we are getting all the documents which
Are coming inside the change feed.
And i'm looking at there's an accident happen or not. Here.
And with this, if there's an accident happen, i just put a
Message on the queue. And on the other end, there are
Different functions listening on
That queue or that web page is also listening on that queue and
They will show exactly where the accidents happen.
Here these four or five lines doing nothing but --
I just showed you these four lines here because i wanted to
Show you what all i'm doing in this function.
But we will see later on that you can delete these lines and
Have the input and output binding concept and then bind
The queue on this function and then return the message and
That's it. So even if i have this few line
Of code, it's hardly 10 to 15 line of code, listening to the
Change feed and alerting. Now, before i can run this, i
Have to set up
This connection strengths.
So here i'm just getting my source connection strength and
Db connection like which connection in the cosmos db i'm
Listening to. And they are defined here
Connection name is this and database is this.
And that's about it. So if i run this function now,
Now you see this function is running on my laptop.
And the queue is in cloud. So this integration is very
Seamless between cloud and other machines. And we can debug it here.
And let me do this. This is
Going to pump some data to show that there's an accident happened.
And when i press this thing and look at my map
And you see it takes five seconds to fall off
Azure function. But you can go down.
That's why you have this option to process the library.
You can go to to second. But millisecond, you will start
-- A lot of cpu. We have just written a few line
Of code to connect to cosmos db and azure functions and putting
This message on the queue and activating my whole micro
Services product. So that was a quick rundown that
How you can use azure functions and cosmos db change feed.
Now let's listen from some of our customer that how they are
Using this power and solving their real business problem.
So i will invite over johnson control, and they are doing a
Lot of things in iot. You have the mic?
>> I have a mic. >>Okay.
Let me go back to the ppt. Next.
>>Great. Well, thank you.
So i'm from johnson controls. We've been in the iot space for
A really, really, really long time.
We got our start way back in 1883 when warren johnson
Invented the thermostat.
He was a college professor and his students were complaining
About the temperature in the room, and so invented this
Device that would allow him to see what the temperature is and
Be able to regulate the control in the room.
We're still doing the same things. We're trying to gather all kinds
Of data and trying to aggregate that together so we can provide
Insights into people's buildings or their cities or whatever else.
But the problem that we found over a long time is that we end
Up with a lot of puddles of data.
The data lake where all the data goes into.
And they don't turn into a lake. They're a bunch of puddles on
The sidewalk that you can't get access to because they're all
Over the place. And we recognized this because
We were constantly trying to write different types of systems
To integrate together to be able to get insights into what's
Going on. We have a piece of equipment
That fails. Why can't we see the warrant equipment with that?
Why can't i see when that was last serviced?
That's what we set out as a company to try to solve this
Business problem for your building information systems.
So when we talk about buildings, there's two chunks of data.
The ot and the it data. The i.T. Data is the things that
Describe the buildings such as what floors there are and what
Sensors are where. But the o.T. Data says this room
Is this temperature, that room is this temperature, and
Whatever is happening in those spaces.
And so we wanted to be able to basically get an insight of
Gathering all of that data together in one place.
And we started off a couple of years ago looking at cosmos as
Basically a document store. We wanted to have a way to be
Able to deploy something in the cloud or on premise.
And away cosmos gave us the opportunity for was that we were
Able to use -- we were able to
Port that over for a cloud scale solution. So we were able to get a lot of
Really quick insights to be able to get that data in one place.
We started realizing that documents was somewhat limiting,
So we wanted to go deeper to join that data together.
And so we started looking at was the gremlin interfaces in cosmos
To join those data sets together. And what was really cool is they
Have the capability that we didn't have to export the data
And re-import it back in. We could use cosmos as a
Document store and a graph store and using gremlin as an
Interface to do that. On the left there, you see all
The different entities. Let's say you have a building,
Building has floors, floors have space, space has equipment.
And we're able to see that logical relationship of those things.
But besides the relationship, i want to actually see what that
Sensor is doing. And we were able to use the
Cosmos as a backend, we were able to aggregate that data so
That you can click in and look at the actually
Telemetry data inside.
And this is really powerful because it's able to give
Customers insight to visibly be able to see how things go.
If you ask three people to come in and describe a building,
You're going to get three explanations of how that
Building is formed. We've used brick, which is an
Open format for describing entities, we're trying to use
That as a standard way to describe that so you're able to
Infer those relationships one way.
So when we talk about -- to the tone of this message of this
Presentation, is how do we use the data, how do we get to the
Data, and aggregate and so forth. When you start talking about
Changing. And if you wanted to graph all
Of the individual raw points, it's going to be really difficult and really slow.
And so typically what we do is we want to aggregate that data
And see what, for a given temperature of room, we want to
See what the daily value is, the monthly value is, the yearly or
Ten-year. So we did the original approach
As we started down as you had the data come in as a sensor.
We sent that to the iot hub, which would then forward to an
Event hub. And from that event hub, we
Would insert directly into the cosmos repository what that raw value is.
But we also want to get that ago get.
So we would shove that to an event hub.
You do all that aggregation to figure out where exactly that value is.
But what you end up is a big feedback loop because the more
Data that comes in, you need to go back out and get those other
Values, pull in, and then do the aggregation and then push it
Back in. And with some of the things
We've talked about is there's an alternate way of doing that.
That sensor pushes into is i.T. Hub and into cosmos.
And you have a change feed that triggers a function and
Aggregate it and shove it back into the cosmos.
You can see it definitely gives it a different behavior in how
Many times you have to touch the data before it ends up in the
Repository and you can query.
We're continually trying to test the boundaries and see where
We're going to be going. Functions is a really great idea
That allows us to be really adaptable.
One thing we're looking at is the idea of moving some of the
Functions to the edge where we can do computation before
Sending it to the cloud. Only send data when you want
Instead of always sending it for all the devices, only send it
When it gets sick. And this will really optimize
The customer's experience. There's a lot of exciting things
Coming up, but we're happy to be part of it and cosmos has been
Great partners for us. And i continue to look forward
To what else will come down. >>Okay, thank you, thank you.
[Applause] >>so let's hear now from andrew.
How are you using cosmos db and change feed?
>> Thank you. Hi, everybody.
My name is andrew. I'm an architect.
If you haven't heard of us before, we're a fashion ecommerce retailer.
It's our mission to be the number-one fashion destination.
We were founding in the year 2000.
It's been a wonderful success story. And we're now a $2 billion a
Year annual turnover in u.S. Dollars.
We engage with our customers through the website, throw our
Native mobile apps and through social media.
The incredible growth we've had over the last 18 years is
Significant to us because we've had to find ourselves moving
Away from our one-prem architecture. So having a website based in
London, sql server based in london, that's no longer an
Option. So five years ago, we ran
Through a big replatforming exercise.
We came across cosmos db and it looked good for us.
It had all these wonderful things. But when the change feed was
Announced during that time, it was a bit of a game-changer for
Us. And i'll explain why.
So we have micro services architecture within asos.
We're using a change feed in a variety of scenarios, but what
I'm going to talk about, the team i used to work can is the
Order management team. Right now we're building out a
Returns solution where you can go to the portal and book your return.
So the idea being you order five items of clothes, you try them
At home and send three back. So traditionally you had to send
The parcel back in the post and you wouldn't get a refund until
They've been received by the warehouse. We're building a portal where
You can book that return online and as soon as the parcel is
Picked up, you get a refund. It's very event-driven.
So from the moment you book the return, it goes into a
Validation process. And then we -- once the return
Has been accepted, then we book a collection with a courier.
So they'll come to your house and pick it
Up. Now we use the cosmos been
Change feed and we choreograph those processes together.
Here. When the collection is booked,
It's going to go into a document generation service and a
Document created event. So here's our handler.
The first thing we do is we load into the previous events into
Our aggregate. We have an immutable log of the
Actions that have ever occurred for that return.
If we need to, we can go back and recreate those events.
Next thing we do after we've we
Generate return document. We download the pdf, save it to
Blob storage. And what we do there is
-- The cosmos db allows another
Service to pick up that change. It's five lines of code.
Really simple to test. It's got an input, an action,
And an output. Being so small and simple, it
Makes it ideal for functions.
You can see here that all of these services are now connected
By cosmos db and the events are flying through the system and
Ultimately ending with a refund at the customer.
What's guide about the change feed prosser is it works on the
Sequence number and you can rewind if you
Choose. We had a third-party system lost
The data. They were struggling to do the database backup.
In the end, we just rewind the checkpoint on the collection and
We just repush through all the events again.
It was up and running in an hour. So we were faster in our
Restoration process. So this is about hosting options.
When we started out a few years ago, we had cloud services
Available to us and cloud services and cloud services.
So we didn't have much choice. Cloud
Services, very low density,
And expensive. You imagine those services.
Then we wanted it in two regions. Before we know it, we've got six
Workers rolls just for one of those services.
Multiply by another 10 or 15 services. We're deploying a load of stuff.
So now the services are more dense.
Pros and cons for each of them. We're now writing all of our
Handlers. It's great news for us, like it
Is ultimate choices between how do we want to host this.
Some other thoughts from me is we had a bit of experience in
Doing this. Some things i wanted to call out.
Some dead lettering is one of them.
We had the dead letter cue. If you're listing code and it's
Listening to messages coming in and your message has changed
Something and there's an error, at least with the asb is it will
Try dead letter. You don't want to get stuck in
An infinite loop trying to process that change.
So you might want to consider writing some code to catch that
Exception and perhaps park the change and deal with it later.
We're hoping soon this might find its way into the change
Feed library. Securities and other things to consider.
For us, we've got some data that has pii information in it.
Personally identified information.
So some other things that have happened recently, so we can
Apply network security group all around it, therefore making sure
Our handlers are only communicating with --
And we're not going out via the public ip.
Now, if you're using the consumption plan, you don't have
That option available to you. So that's something to consider.
It might affect your choice of how you use your functions.
At that point, you might want to start thinking about the app service plan.
The other thing i wanted to talk about is run time.
That's another option available to us.
You can have your function run time hosted in a container and
Then you have the best of both worlds. You have the nice deployment and
Development model, but you can choose to host it
On your choice.
We love it. We're using it lots and lots
Now. We really like it.
[Applause] >>thank you.
>>Thank you, andrew. Thank you. So before we get into the
Question and answer, give me just a minute.
I want to show you the thing i was talking about binding.
So this was the code i wrote
Where i am --
But if i want to turn it into binding, all the code line goes
Away and i just write one here. And that's it.
And jason will have the information about connection.
It's saying the binding out. So in my function, i'm just
Returning a message and that's it. So just i wanted to show you
Quickly how simple everything becomes. Now let's have a question and answer.
Chris is with us. He's one of the founding members
Of azure functions. So we heard so much about azure
Functions. Now he's kind enough to come in
This session to answer all of our questions.
And one more interesting thing is he joined cosmos db, too.
So come on, chris. >>Hey, how's it going?
If there's any questions on cosmos db azure functions, we
Can field them here. We actually used the change feed
For that red t-shirt demo that you saw during the keynote.
That's what i spent my last three weeks trying to get that
App in lightning fast, so tuning lots of knobs.
For the most part, latency was 700 milliseconds, which is
Pretty good. >>And if you don't want to ask
Questions now, we'll be down there in the booth until the evening.
Come there and ask any questions. >>I have a question about
Disaster recovery. What's the story behind that?
So when azure functions somehow does a big disaster and you
Start to recover from that, how do you make sure that you are
Handling all the changes that will pass through?
>> Yes, that's a good question. If you're using the change feed
Processer, you're using the change feed trigger for azure
Functions, effectively what's happening is it's using the
Change feed processer host. That same checkpoint inside of a collection.
So if it's not responding at all, the checkpoint's still saved.
So what you can do is you can point a brand-new function.
You can take the exact same code and settings and point it at the
Same collection and it will resume at the previous point.
That's how you make sure you never lose that state.
You can also change that checkpoint if you wanted to go
Back in time and replay events. Let's say the whole region's
Down. Send to another region and it'll
Resume reading from that region. >>Can you get a change delta
For a record? >> what you get is the final
Form of document. So whenever you ask for the
Change feed and there were changes that happened before
That, they will be lost but you can get to the final form.
All the changes will keep coming to you.
>>But my suggestion, you can really look at doing the event
Source and type of pattern. Each record, you're just
Depending changes you want to have happen.
And your document being modified is the changes.
And your materialized review is where you reflect those
Changes. >>All right.
We talked about the event source. Could it be
Outside azure as well?
>> Sorry. You are asking can you hear the
Change feed from outside of the cloud? >> it could be a change feed.
It could be a change feed. Maybe an item of some records on
Changing up some records on cosmos db, as you said, or it
Could be a message on a -- but could it be outside of azure?
That source, can it be outside azure?
One is cosmos db is only on the cloud.
But if you have other services which you want to trigger the
Functions, there are options. >>What i recommend looking into
There is you have the more classical case of using relay as
An integration when your on-prem services and cloud services.
And then that function is running in the cloud
Using those. One of the more kind of new ways
Of doing this might be using something like event grid.
It's great because you can publish events and have
Functions and other things listen on those events.
I'm kind of leaning to event grid as one of the newer
Ways to do this. >>Thank you.
>>Just a quick question about your demo code there.
You were processing all the changes as they come in.
Is there anything inherit in the function's run time that will
Paralyze that? >> so, when you are writing the
Function, it is basically your c shop code.
And you can do there anything. You have a list of documents
That's come to you for the simple -- as i just said, i'm
Going through the loop. But you can take it and paralyze
Or do anything. >>But inherently in that
Function, there's only one copy of your function running?
So functions is -- so one important thing to think about
With the change feed sser
Is you have to be taken off the partition in order in order to
Maintain what your checkpoint state is.
And functions automatically will scale you out and make sure
You're getting maximum scale for the number of partitions that
You have. That letter handling is
Important because if you block the processing because you have
A bad message inside of there, your whole partition is slowed down.
You want to take the bad things, dump them into a queue and then
Keep processing the feed as fast as possible.
>>If you wanted to further paralyze within that, you could
Shell off to another function. >>You could do batches of work
From there. >>When you are using the
Processer and you can start six or ten instance off an app which
Are listening to the same change feed, it's smartly divide the
Partition between the -- it ignores -- two apps have come to
Listen, so it will give five partition. And you do have your own -- you
Can write your own write the
Work. >>Hi.
So quick question. Does the change feed account for
Requests if i have a request coming into my database and i
Have change feed events. Does that account for my questions?
>> For audio, yes. Because the data is moving out
Of the database. >>It's not necessarily
Doubling your rus because reads are
Cheaper that i know rights. But you can look on the actual header.
As you're using it directly from your cosmos db stq.
It's not the same as right
-- Writes. It's much cheaper than that.
>>Then you are using the processer library.
That will be extra cost on you because we keep all the
Bookkeeping on the lease. So there's one more collection
That's created by the change feed.
Feed. >>How does it work with a
Function app if you need to install a package?
>> That's a good question. There's two options.
You've got the csx model. And then we go ahead and do the
Restore at startup time for the function app.
I don't recommend that pattern to do for people trying to do
Something more robust and long term. It's a great way to get started.
But long term it's best to use the visual studio for project functions.
And that's a class library with annotations in it that we then
Load and use those annotations to figure out this is the
Function we're going to call for this particular event.
That's the annotations you saw. There you manage them like you
Do for any class library. Choose whatever packages are
Compatible with your functions and it should just work.
>>Will it work if the package is on a private repository?
>> Yes. You'll need to make sure that
Your visual studio or cd pipeline has access to that
Private package. But the function run time
Doesn't need to know about where it came from.
You're shipping the binaries
When you deploy to it. >>Okay. Thank you, everybody.
They are looking for people to help us build the next
Generation. So please try this.
[Applause] >>go ahead.
>>Just wondering if the functions is the future for
Replacing completely -- or it's just going to complement that?
>> It's definitely a complementary story.
Things where you want high control. That's going to be its domain.
You definitely want to think about the offerings that
Microsoft has, old and new, as a spectrum of things where we're
Trying to give you options for high-control scenarios and
High high-productivity.
On the other side of things with something like running your own
Stuff on top of your own vms and you have things like aks with
Aci, then you kind of move into app service land where it's
Still instance-space pricing but the front end is taken care of
For you and then at the very far right, you've got functions.
You can think of it as a spectrum of offering depending
On what you need. If you want more control, you
Can use something on the left, as i call it.
And then if you're trying to just be fast and quickly get
Something out, functions is a great choice.
My biased opinion is to always start with functions is because
You can start fast and fail fast and then move to something else.
If you move to something out of the box, it'll be hard to give
Up control as you move through the functions.
That's my advice. >>Thank you. >>Okay.
