Unlocking Serverless Potential

## Metadata
- Author: [[YouTube]]
- Full Title: Unlocking Serverless Potential
- Category: #articles
- Document Tags: [[video-notes]] [[youtube]]
- Summary: Unlocking Serverless Potential
- URL: https://www.youtube.com/watch?v=bNOfI6zGK7E
Ivelina Dimova: Thank you, Brian. So I'm Ivelina and I have the hard
task to wake you up after lunch. And I have bad news for you today. I'm not one of these very fun
speakers and I usually talk about code, so I'm sorry in advance. So I'm a senior developer at Awesome
Motive and a few years ago I started working more with Google Cloud. As a part of that, I subscribed to
their program, and in that program they
sent every week a newsletter called The
Overwhelmed Person Guide to Google Cloud. And that makes it even more overwhelming
because they list every week so many new products and services and. It's such a huge platform that is
very hard to grasp if you should now use compute engine or event
tech or fair base or whatever.
So today I try to focus just on a
few examples that you can use to include in your WordPress development. Yeah, it works. So why Google Cloud? It has global infrastructure. There are datasets all around the world. It's can be used as a serverless
infrastructure, so we can offload all that server provisioning,
monitoring, and so on to Google Cloud.
There are several. Like actually there are many
AI and machine learning options that you can use to include AI
in your WordPress or projects. And also they are developer friendly
tools like login, tracing, usage information and client libraries. Let's first see the serverless options. Cloud functions. These are single purpose event
driven functions that can be respond
to triggers like HTTP request,
uploads or database changes. They can be used for webhooks,
for third party integrations be used for cloud shadow, which
is like a CRON job based task. If you need more control,
you can use Cloud Run. That's a container based serverless
platform where you have more control over the container. The setup, you can address any language
or binary unit, and you can scale from
zero to many instances in traffic spikes. You also don't pay anything
when the instances are not used. Oh, that machine learning that
is so popular recently, you can use it with vision ai. Vision AI detects images,
faces, and landmarks in photos. It can be used for image
tagging, content moderation,
and for accessibility features. With natural language ai,
you can create summaries. It's ideal for SEO optimization,
recommendations from blog post and content moderation. Translation AI can help you translate
your project in more than hundred languages with high accuracy, and
help with real time translation of blog posts or user comment. And of course Vertex ai where you
can also import your data and you can
train your models, save them, and build
intelligent chatbots that answer questions from users on your website or generate
content if that's what you want to do. So I know that that's like a lot to grasp,
but let's not go to the overwhelmed person state and see a few practical examples. So, for example, automated media
processing, I dunno how Brian knew
that he's never seen in my slides. But one example for using that
architecture is intercepting media approach with a workplace plugin,
sending it to a cloud function. Then analyze the images with vision ai,
generate metadata for your WordPress website and optimize the image. Another usage can be
intelligent content insights.
You can use natural language AI to
extract entities for SEO, create summary for long blog post and
help the users understand them. You can also analyze comments and
create option for your creators to understand better the user engagement. How that can be accomplished. You can use natural language AI with
PHP client libraries and process the
content on safe or to background jobs. Real-time multilingual support. You have here, as we said,
cloud translation ai. So you can translate on demand
or you can create dynamic page selection with widgets. Then send the data to a cloud run
function and detect it, translate it, and eventually also catch
it in your WordPress database.
And everyone's very favorite AI
power chat box, as we said, you can leverage here Vertex ai, where
you can personalize the model. You can import your content, train
the model, then create a cloud run backend in your favorite language
and pay only for the usage. We integrated it WordPress with a
widget or whatever content you prefer.
And last but not least, another thing
that Google Cloud is very useful for is because it has all these quiet libraries
that integrate with Google Drive services. For example, you can leverage or sending
the data from your WordPress website to Google Sheets, with Google Sheets
API analyze it and give more control of your employees to go to the data,
create more visualizations, and so on.
And to get a better demo for
that, I will try to get a deep dive into the media processing. I'll show you the code, but I
didn't want to show only the code, so that's just an overview here. So this example leverages the vision
AI for any detects in domain images, objects, texts, faces, landmarks,
detects auto also appropriate content.
It generates automatic metadata,
implements performance optimization by processing the images and
storing them in cloud storage. What is the benefits of that? Of course, that can vary much from
business to business and depending on how you are doing the image on your sites. But you can leverage from eliminating
the manual, um creating of outtakes,
tagging the images, organizing them. Also, you create some better performance,
bug saving the image in side size. Technical architecture is
just a WordPress plugin. The WordPress plugin intercepts, sends
the data to cloud function, vision ai, as we reset goes to the image, then
it turns the metadata to WordPress
and the WordPress plugin
is not that complicated. It use just few well known hooks
intercepts the media upload or attachment depending on what you prefer. It can also be used on a CRON job if
you don't want to disrupt your user experience with waiting and since to
Google Cloud function for process. The cloud function in my case uses
Python, but you can use whatever you want.
Just in my experience. Python works way better
with image manipulation and optical chapter recognition. The quote function is we said scales from
zero 2000 of executions very quickly. You pay only for the compute time and you
can use the built-in login mechanism. Here I have to say that the building
error handling does not work the same way that I personally expected.
So if you don't lock everything
in standard error or standard output, you'll never see a thing. And you just wonder why
that thing doesn't start. So lock everything and log it in that way
because with error work and other print functions in PHP, you never see error. And when that goes to the image and
process it, it sends it to vision ai. Vision AI does its analytics,
the image being optimized
and stocked in cloud storage. How vision AI works. It identifies in localized objects
with confidence codes like shown here, like how many confidence
codes it has, the dots on the image. Then it performs optical tract
recognition, extracts text from the image, identifies faces and
emotions, and detects landmarks. It also detects safe search.
It performs a safe search and
detects inappropriate content. Very simple example, image with
the beach and sand palm trees. Vision AI goes to it. There are the, I guess that's too
small, but that's the confidence code of what it finds in the image then
generates human readable outtakes, a vibrant sunset over a beach. silhouette palm trees in the ocean.
I couldn't write that. And it generates text beach
sunset boundaries and so on. Image optimization. You can resize the images, smart
comprise them, or if needed, you can also for for convert the format in
whatever you need for your project. Then you can use cloud storage
to leverage CDN alike structure and serve them on the front end.
Content moderation. As we said, vision AI goes to the
imaging, performs a safe search. It identifies adult content,
medical imagery that can contain some sensitive content, violence or
misleading and manipulative content. Then main interface is super simple. It has a settings management where
you add your cloud project id, your
HTTP link for the function execution
and the cloud storage bucket. You also have processing
dashboard where you see how fast the images being processed. Activity logs and some feature controls to
decide how many tasks you want to generate what such to perform for AI and so on. How that works in GCP, you are going
in there and create a new project.
You can also do all that with
Google Cloud, COI, which is given as an example here. You can do it in the
web interface as well. Create a new project, connected
to a billing account because you have to pay something at some
point and enable the required APIs. Here we need vision cloud Vision
API, cloud Storage API, cloud functions API, and Secret Manager API. As I got to the secret manager, I
need to mention service accounts.
Service accounts, or accounts that
calculated to a service and I'm not identified with the person. They have their unique email addresses
and can be authenticated using RSA private and public key pairs. They are used to call the Google API
services, and it's very important to give them the needed identity
and management access because otherwise it'll fail silently and
you wonder why it's not working.
Secret Manager is another
service that you can use to encrypt and store sensitive data. It has versioning. In your audit logging, you can
see the versions of your secrets. You can stock their key
pairs for the service account. You can also use tokens, for
example, you can store an encrypted token of the WordPress
side, and when you send the data.
To the HTTP request to the cloud function. It can recognize it via secret main
to token and compare both to see if that's where the data is coming from. So here we give the service account the
needed permissions, assign the goals. We always should assign the goals based
on the principle of lease privilege. So we give them only the access
that they need and then generate
the service account key. Store it in secret
manager and we are done. I guess that's stupid small, but I will
upload the slides for you to see it later. We do the cloud function. As I said, you can use whatever
programming language you prefer in that situation. I've done the same thing with PHP Python. It's just, I love Python lately. So the example is in Python,
and when you finally deploy,
oops, you get the function URL. You test the WordPress plug and
connectivity, adding the data there in the settings, and you are ready to use it. If you don't want to do all that. No. Anyway, so that's supposed to
be demo of uh vs code because vs code or whatever you use, have a
free extension for Google Cloud.
Here you can deploy your cloud function
and you don't need to leave your editor. You can also see the, uh. Secret that you've stored. You can go to testing locally,
so you don't need to deploy every time when you change something. And also you can leverage Gemini
code assist, which can help you with deploying the function, developing it. Of course, everyone uses
some AI helper at the moment.
I personally use cursor a lot. And mainly I use Clouds SONET, or
something like that from a topic. But I got to a conclusion,
especially working on that demo, that for Google Cloud, services,
Gemini of course, does much better because it's in the same ecosystem. And that's a very, very convenient
way to deploy everything without going to the terminal or going
to the web, to the web interface.
And. It actually worked. What did they do? So apparently I should press next. Okay. So now it shows how you
actually can deploy that. I was just thinking that I did such a
smarting and I encoded it instead of doing live demo, because I've done live
demo before and that's not a good idea. So yeah, it has the secrets, it says the
disabled versions and the cloud storage bucket and everything that you need to
see for the project in the same place. And that's very handy.
And now I know how to play a demo. So that's the demo of that plugin
that I created for LoopConf so that's its setting page here. You can see that it has the fields for
the Google Cloud functions and so on. And if you come and put the
image here, I gave it just, uh. One of these fancy images that
the building generated for me. I went to New York recently and
you can see that it's processing
the image here eventually. I dunno how much you can see from that. And in the end, it generates the in
front of, in Spain that build, they building a description, the
out and the processed media sizes. Also the safety score in the bottom. And if you go to the front end and
check that image, you'll see that now it's so from Cloud storage,
not from the WebPress site.
So that was the demo and. I just wanted to mention in the end
that if you need to add database to your projects in Google Cloud,
you have like 10 different options. The most popular, of course, are
Cloud SQL, which is normal SQL post SQL database service or file store
where you can store documents. you can of course use memory store
and BigQuery, which have different
abilities depending if you need to
cache something or you need big queries. And in my experience, another very
useful thing is cloud scheduler. Cloud Scheduler performs any current
jobs depending on whatever task you want to execute, and it can call cloud
functions, the automatic media processing, depending on the shadow that you need. So I know that I went
through that very quickly
but. Key takeaways of the whole thing
is that you can use architecture and eliminate all the keeping
that in your WordPress project. Also, you can do that to use other
programming languages, which I love, and you can pre-train your machine
learning APIs to provide personalized data and machine learning experience. Also, you pay on the go
and that reduces the cost.
There are several resources to get started
and I'll upload the files somewhere. Questions? Yes. No. Brian Richards: Amazing As expected. If any of you have questions, we do have
just a minute or two and I can bring a microphone to you if you put your hand up. And if not, that'll help us catch
right back up after all the delay.
here we go. Mr. Blackburn. Ivelina Dimova: Just, just, just
one second, John, I'm sorry I didn't plan to do that, but as we
have time, I just wanted to show you what that does in the Python. So let's keep the logging, which. Yeah. it gets a secret from that secret
manager to checks if that function is coming from the same time, verifies
the tokens and then process the image.
So. It goes to it and then here in the vision
ai, it contacts vision ai and then it performs all these things like label
detection, object, object localization, text detection logo, web detection,
image properties, and that's where it logs the data in it and gets the
results for all these things, passes
them and gets them back to WordPress. I just wanted to quickly scroll to that. Yes, John. Go for it. Question: Great. thanks, Ivelina. Great. Really interesting. What's the performance like? Like if I upload an image and it does all
this processing, is it gonna be subsecond? Is it a few seconds? Ivelina Dimova: So the code start for
the cloud functions is like subseconds. It's in my experience at
least, it works quite fast.
It, of course, depending where you put it,
like when we have service in the states, I use, like time zones in the States. So again, you can put it in
several time zones so you can be able to scale it faster. Brian Richards: Amazing. Anyone else? I thought I saw one more hand tentatively
go up as I invited you to ask questions, so I don't wanna cut anybody off. Yes, you the distinguished
gentleman in the back.
Ivelina Dimova: I'm sorry I missed
you talk, if that's about it. Question: No, that's not it. I just wanted to ask so you're
using Google Cloud platform here. Have you also explored other serverless
function providers, CloudFlare workers? is there a strong preference for Google
Cloud over the others, if you have, or how do you think about the different options? Ivelina Dimova: Yeah, so while AWS. And as you probably like, they have
similar functionality of course, but
first, a lot of the companies already
use Google Cloud services for many other things like Google Sheets, Google
Drive, you know, store documents. So the organization already knows it. And having code this client libraries
to sent your data from WordPress to Google Cloud helps a lot. And second, as far as I know,
and I'm not the billing person to answer that question correctly, it's
cheaper because when it's not used,
use pay only for the compute time. So when the function is not in
use, you don't pay anything. Brian Richards: That's awesome. That's a really good
selling feature right there. It's easy to win when you've
already got all of the momentum of being in all of the places. Was there one more? Anybody else? No. Amazing. Well, another round of
applause for Ivelina Thank., Unlocking Serverless Potential, YouTube, 01k9avbjxb6mqccj43hhrtqq4j.