Giter Site home page Giter Site logo

api-router-engine's Introduction

API-Router-Engine

Strategy Pattern & Dependency Injection

  • Vendor and RouterEngine Class
  • Vendor has state for traffic quota, availability and stats
  • Router engine has state of vendor list and route strategy
  • Different strategies for routing injected during runtime as method
  • Same set of checkpoint and recalculation functions works around those strategies, keeping same behaviour intact but with different intent
  • Decorators can be added for checkpointing and book-keeping

Simulation

self.run(): 
  
  self.set_vendor_availability():
    for vendor in vendor_list:
      for each row in opened vendor csv:
        vendor.is_available = row[‘API Available’]
  
  self.cater_request_output():
    for row in opened request time csv:
      ans = self.route(row)
      write ans['Request Index', 'Vendors tried'] in output csv

Strategies

  • Dummy Route : Route all request to vendor1 Some requests are never fulfilled, when vendor1 is down
  • Simple Route: Route request to vendor1, if it is up, else to vendor2 and then, to vendor3 in order All requests are fulfilled but the request tries the order
  • Steady State Traffic Route : Route request based on steady state traffic quota only
  • Dynamic Traffic Route: Routing request based on dynamic traffic quota based on failure & comeback

Dynamic Traffic Route Algorithm

def route_dynamic_traffic:
  a = get_index_multinomial_single_roll(traffic_prob_list) 
  for vendor in self.vendors_list[a:]:
    vendor_tried_list.append(vendor.label) 
    self.checkpoint_till_time_sec(vendor, time_sec) 
    if vendor.is_available[time_min - 1]:
      heappush(vendor.stats['success'], time_sec) 
      write_row['Vendors tried'] = '|'.join(vendor_tried_list) 
      break
    else:
      heappush(vendor.stats['failure'], time_sec)
  traffic_prob_list = self.recalculate_traffic_prob(time_sec) 
  return write_row

api-router-engine's People

Contributors

jayanthkmr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.