Performance: API versioning with blueprints
MEDIUM IMPACT
This affects the initial server response time and routing efficiency, impacting how quickly the API can handle requests for different versions.
from flask import Flask, Blueprint v1 = Blueprint('v1', __name__, url_prefix='/api/v1') @v1.route('/resource') def resource_v1(): return 'v1 data' v2 = Blueprint('v2', __name__, url_prefix='/api/v2') @v2.route('/resource') def resource_v2(): return 'v2 data' app = Flask(__name__) app.register_blueprint(v1) app.register_blueprint(v2) if __name__ == "__main__": app.run()
from flask import Flask app = Flask(__name__) @app.route('/api/v1/resource') def resource_v1(): return 'v1 data' @app.route('/api/v2/resource') def resource_v2(): return 'v2 data' if __name__ == "__main__": app.run()
| Pattern | Routing Table Size | Request Matching Speed | Server CPU Load | Verdict |
|---|---|---|---|---|
| Single app with all routes | Large (all versions combined) | Slower (linear search) | Higher (more CPU for matching) | [X] Bad |
| Blueprints per API version | Smaller per blueprint | Faster (modular lookup) | Lower (efficient matching) | [OK] Good |