How to rate limit an API call using custom configuration?












0















First of all thanks for everyone that can provide his feedback on the problem or share some thoughts about my solution. Hoping everything is clear this is my problem:



In my project, I have a controller action under a specific route path (URL) that allows me to call a third party web service to retrieve some external informations. This controller action, in order to call the third party web service, needs to fetch some access data from the database based on the logged in user.



At this point I need to rate limit my controller action to be able to limit the external web service API calls based on a customizable configuration that have to be used along with the access data.



Example: User A visits "/myURL". The controller action recognize Users A and fetch his access data from the database that allows him to retrieve informations from the external web service.



If I need to add some rate limit configuration that will prevent Users A from using, for example, more than once per seconds those access data and then calling the external web service, where do I have to store this configuration? How should I retrieve and use these configurations in order to provide good performances and avoid hitting the database multiple times?



The solution that I found:



I'm storing the rate limit configuration along with the user access data inside the database. I'm caching the same rate limit configuration along with the number of requests that have been done. When a new request is hitting the controller action, I'm retrieving and updating the rate limit data inside the cache. In this way I will be able to customize (or let the user customize) the rate limit values stored in the DB and avoid stressing the database with multiple read/writes when I need to use them. The database will be used just to hold the rate limit configuration that, when updated, will replace the cached configurations.










share|improve this question





























    0















    First of all thanks for everyone that can provide his feedback on the problem or share some thoughts about my solution. Hoping everything is clear this is my problem:



    In my project, I have a controller action under a specific route path (URL) that allows me to call a third party web service to retrieve some external informations. This controller action, in order to call the third party web service, needs to fetch some access data from the database based on the logged in user.



    At this point I need to rate limit my controller action to be able to limit the external web service API calls based on a customizable configuration that have to be used along with the access data.



    Example: User A visits "/myURL". The controller action recognize Users A and fetch his access data from the database that allows him to retrieve informations from the external web service.



    If I need to add some rate limit configuration that will prevent Users A from using, for example, more than once per seconds those access data and then calling the external web service, where do I have to store this configuration? How should I retrieve and use these configurations in order to provide good performances and avoid hitting the database multiple times?



    The solution that I found:



    I'm storing the rate limit configuration along with the user access data inside the database. I'm caching the same rate limit configuration along with the number of requests that have been done. When a new request is hitting the controller action, I'm retrieving and updating the rate limit data inside the cache. In this way I will be able to customize (or let the user customize) the rate limit values stored in the DB and avoid stressing the database with multiple read/writes when I need to use them. The database will be used just to hold the rate limit configuration that, when updated, will replace the cached configurations.










    share|improve this question



























      0












      0








      0








      First of all thanks for everyone that can provide his feedback on the problem or share some thoughts about my solution. Hoping everything is clear this is my problem:



      In my project, I have a controller action under a specific route path (URL) that allows me to call a third party web service to retrieve some external informations. This controller action, in order to call the third party web service, needs to fetch some access data from the database based on the logged in user.



      At this point I need to rate limit my controller action to be able to limit the external web service API calls based on a customizable configuration that have to be used along with the access data.



      Example: User A visits "/myURL". The controller action recognize Users A and fetch his access data from the database that allows him to retrieve informations from the external web service.



      If I need to add some rate limit configuration that will prevent Users A from using, for example, more than once per seconds those access data and then calling the external web service, where do I have to store this configuration? How should I retrieve and use these configurations in order to provide good performances and avoid hitting the database multiple times?



      The solution that I found:



      I'm storing the rate limit configuration along with the user access data inside the database. I'm caching the same rate limit configuration along with the number of requests that have been done. When a new request is hitting the controller action, I'm retrieving and updating the rate limit data inside the cache. In this way I will be able to customize (or let the user customize) the rate limit values stored in the DB and avoid stressing the database with multiple read/writes when I need to use them. The database will be used just to hold the rate limit configuration that, when updated, will replace the cached configurations.










      share|improve this question
















      First of all thanks for everyone that can provide his feedback on the problem or share some thoughts about my solution. Hoping everything is clear this is my problem:



      In my project, I have a controller action under a specific route path (URL) that allows me to call a third party web service to retrieve some external informations. This controller action, in order to call the third party web service, needs to fetch some access data from the database based on the logged in user.



      At this point I need to rate limit my controller action to be able to limit the external web service API calls based on a customizable configuration that have to be used along with the access data.



      Example: User A visits "/myURL". The controller action recognize Users A and fetch his access data from the database that allows him to retrieve informations from the external web service.



      If I need to add some rate limit configuration that will prevent Users A from using, for example, more than once per seconds those access data and then calling the external web service, where do I have to store this configuration? How should I retrieve and use these configurations in order to provide good performances and avoid hitting the database multiple times?



      The solution that I found:



      I'm storing the rate limit configuration along with the user access data inside the database. I'm caching the same rate limit configuration along with the number of requests that have been done. When a new request is hitting the controller action, I'm retrieving and updating the rate limit data inside the cache. In this way I will be able to customize (or let the user customize) the rate limit values stored in the DB and avoid stressing the database with multiple read/writes when I need to use them. The database will be used just to hold the rate limit configuration that, when updated, will replace the cached configurations.







      database web-services caching throttling rate-limiting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 12:23







      Andrea Loprieno

















      asked Jan 2 at 21:09









      Andrea LoprienoAndrea Loprieno

      86




      86
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013227%2fhow-to-rate-limit-an-api-call-using-custom-configuration%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013227%2fhow-to-rate-limit-an-api-call-using-custom-configuration%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          How to fix TextFormField cause rebuild widget in Flutter