title: How to design an extremely fast python HTTP API with data lookup (>15K req/sec)?
body: <p>I need to build a REST API/server which responds to more than HTTP GET 15,000 requests per seconds in under 80ms. If necessary I could run multiple instances with a load balancer.</p>
  
  <p>The server gets a request with a list of criteria (around 20), they need to be parsed and compared to a ruleset (about 2000 rules which have different values for all 20 criteria and a final decision) which decides the response (yes or no).</p>
  
  <p>Sample Request payload:</p>
  
  <pre><code>{"Country" : "DE",
   "ID" : "998423-423432-4234234-234234",
   "Criteria1": "8748r78",
   "Criteria2": "Some String",
    [...]
  }
  </code></pre>
  
  <p>Sample ruleset (still to be decided, but let's start with a simple design):</p>
  
  <pre><code>+--------+---------+-------------+--------------+
  | RuleId | Country |  Criteria1  |  Criteria2   | etc...
  +--------+---------+-------------+--------------+
  |      1 | UK      | SomeString1 | SomeString3  |
  |      2 | UK      | SomeString1 | SomeString2  |
  |      3 | US      | SomeString4 | * (Wildcard) |
  +--------+---------+-------------+--------------+
  </code></pre>
  
  <p>Every criteria can contain between 1 and probably around 400 different values, all strings (e.g. GEOs in ISO Code). Some might be empty and be treated as wildcards. Theoretically there could be entries with all 20 criterias having the same value, but that is a topic for the yet to be written rule engine to sort out.</p>
  
  <p>I did some research how to achieve this:</p>
  
  <ol>
  <li>Using sanic as a webserver for a high throughput, according to my
  research this is the fastest for python excluding japronto which is
  in alpha; Edit: Does anyone has experience with the performance of a python based webserver+webframework regarding a similar usecase? I only read benchmarks which usually have a very simple testcase (just respond a fixed string to a request, therefore the high number of possible requests per second in all the benchmarks)</li>
  <li>Using sqlite3 (in memory) for rule lookup; not sure if a SQL statement with 20 constraints is fast enough? Maybe there is another
  way to compare every request to the ruleset over 20 criteria (each
  one is a string comparison). EDIT: Thanks to a commenter I might precompute the rules into hashes and use hashes for lookup, thus a database for the real-time lookup is not needed. </li>
  <li>Use redis or another database to store the rules precomputed (that
  is another topic) and make them ready to get loaded in every
      instance/worker of the http server and thus sqlite3 database.</li>
  <li>Maybe use pypy3 for additional speedup, but I have no experience
  with pypy</li>
  </ol>
  
  <p>I would host this on Heroku.</p>
  
  <p>So the question is: Which libraries and thus architecture would allow that kind of speed with python?</p>