
Ask HN: System Design – Fastest webserver to serve data in memory - pastaking
### The Task<p>Imagine we&#x27;re making a webservice called &quot;Primes&quot;. It has 1 endpoint, something like this:<p><pre><code>    from flask import Flask
    import random  

    app = Flask(&#x27;primes&#x27;)
    
    @app.route(&quot;&#x2F;rand_prime&quot;)
    def rand_prime(n):
        return random.sample(primes, 1)
    
    if __name__ == &quot;__main__&quot;:
        global primes
        # some function to load primes from a file into a set
        primes = load_primes()
        app.run()
</code></pre>
We want the <i></i>fastest webservice<i></i> to serve this endpoint that handles as much QPS as possible.<p>### Constraints<p>- We have to load all the primes __into memory__, there&#x27;s no database at all. 
- We cannot use memcache, redis, etc.
- We have to use Python.<p>### Current Solution<p>The code above just serves the primes via the default webserver that comes bundled with Flask. Some ideas to improve upon this:<p>- Use a better webserver (eg. Tornado)
- Proxy several instances of this behind an Nginx server<p>Can we make this even faster? We really don&#x27;t need complicated routing or security... Is it possible to do better by writing a custom webserver?
======
nwrk
Huh, why to reinvent a wheel ?

G-WAN
[http://gwan.ch/imgs/gwan_hello.py.png](http://gwan.ch/imgs/gwan_hello.py.png)
[http://gwan.ch/developers#tab8](http://gwan.ch/developers#tab8)

