I have built this in Golang called Gothrotal, a rate limiting reverse proxy.
00:09
Let's discuss the architecture.
00:14
So when we discuss about the proxies whenever a users Visit the/auth route it Proxies the request to auth service which is one microservice running independently.
00:30
And similarly when you visit slash API it proxy request to API backend service which is also running independently.
00:40
And this is a proxy, I'm talking about this, this thing.
00:45
This is a proxy server which is the main the main server which proxy your request to that.
00:51
And it also has a rate limiting system.
00:54
So it uses token bucket algorithm which tells like if you have the token then it will forward a request to the microservices else it will block your request and it will give you a rate limit.
01:10
And you can describe the number of requests per minute per second and the burst token and all.
01:19
Every request it will consume one token.
01:22
and after a certain time it will refill your token as per the algorithm.
01:29
And again the loggers is there.
01:31
It will check it will check based on your client ip.
01:35
So if you are routing, if you are making request from 23 means one single IP then it will block your request after some time as per the config file.
01:46
And if you at the same time if you are hitting the request from different IP it won't block you.
01:53
So it's based on per IP a client ip.
01:58
And yeah, this is like the user or the client which make the request and this is all about it.
02:06
Let me go ahead and show you the file structure and all.
02:13
So this is as I have discussed that it It has been built on golang and the file structure if you can go.
02:23
So you can see there is a binary file, all the binary files which I have built and this is the main file that is a proxy which I will tell you.
02:31
But before that let's discuss what the main thing internal rate limiting, how it's happening.
02:36
So I'll go to internal folders and there's a rate limiting and rate limiter.
02:42
Go, go.
02:44
So There's a allow folder.
02:49
Yeah, so this is the main thing which is taking care of the request for blocking rate limiting.
02:57
This is the algorithm It fills you at the starting and If the time, if the token is ending and has greater than one then it will Minus the token.
03:10
Like it will reduce your token and basically it consume your token and then It will forward your request which is done using the middleware.
03:18
And talking about the middleware you can see the rate limiting middleware I have made which is called limit and it allow based on your client ID only.
03:31
So this will be the error if the rate limit you have exceeded.
03:36
This you can see this is the Client ID is equals to client IP and you can now come in the main file the full entry point of the file.
03:48
You can see I have used GIN framework for the server and before that let me go ahead and tell you that how these all thing is happening.
04:01
So I have built Like config configuration where you can tell all the things you want to do in your whole services.
04:13
Like you can define how many paths are there, how many target you want.
04:17
Like these are the different services which are running and this is the path.
04:22
For example This thing running on port 8080 and if you go slash API it will redirect you to port this localhost 8000.
04:32
And similarly the rate limit request is there.
04:35
You can mention request per minute or request per second.
04:39
You can mention 20 request per second and the boost is basically Like you can simultaneously make four requests and then after that it will block you for some time.
04:51
So basically if you are using 20 then per minute means 60 second divided by 20 it will give you around 0.33.
04:59
So four second four is there means it will consume around four second to fill one bucket, And yeah this is all talking about this one the main middleware I was talking about.
05:14
So it uses the loggers as you can see and the middle age which I showed you like that is the same it's using here as well as eight uses here like no request proxy handler.
05:35
So let me show you how to run this file and all.
05:43
So as you can see there's a binary file and you can also see there are so many sale command which I have made to in order to run the programs.
05:51
So I'll go into shell and start the demo.
05:56
As you can see the Goro tutorial demo environment is building.
06:00
So it will build all the file system and it has two examples right now.
06:05
API server and auth service which will also run this is like two independent service which are running.
06:12
this is the CMD one proxy.
06:15
It's a different service which is the Main service which is running on Port 8080.
06:20
You can see that and yeah starting go throttle reverse proxy which is running on port 8080 and it has loaded the configuration from config file this config file.
06:36
And this is basically done via YAML.
06:40
So we have also use the YAML parsing libraries which is like port server 8080 rate limit is 20 requests per second and this is a 0.33 request per second bus time is 4 and request route is API it will go here and the second route is this.
07:01
So let's go ahead on the browser and see it in action.
07:08
So if I go and put 8080 and if I if it is running the main service running with us health check then you can say that it's healthy.
07:18
And similarly if I go directly on slash API you can see that That is whole thing is proxying proxying the request to API which is directly running on port number 8,000.
07:35
this thing is an independently running on 4000 8001.
07:40
Again this is the auth service 9000 it's running on but whenever we go and see the/API/authentic it will proxy the request to that server.
07:55
And if you hit concurrent like continuously if you hit the service on this route then it will rate limit your services also.
08:06
So let's see it in action.
08:09
I'll like basically make the request by reloading it and as you can see So we had mentioned four request has the bus time.
08:18
So after the four request it blocked you and after four second it will like token bucket will fill.
08:26
So as you can see it has become active.
08:29
So this was Thank you so so much for watching this demo video.