Mitigating High-Traffic with Simple Static Content Generation
A Software Engineer passionate about public good projects and making technology to serve society en masse.
Search for a command to run...
A Software Engineer passionate about public good projects and making technology to serve society en masse.
No comments yet. Be the first to comment.
HS (Harmonised System) Codes help classify customs authorities and businesses around the world to ensure appropriate import/export control. This system recursively classifies a product into finer granularity of categories. Figure 1: A simple exercis...
Jan allows you to deploy and run LLMs on your Windows or macOS computer! 16 Gigabytes of memory and a M1 chip was enough for me to run Mistral locally. Now how do you take Jan and use libraries like Langchain? https://jan.ai Local API Server Click ...
My talk at PyCon Thailand 2023 on the security aspects and possible attack vectors of LLM Applications, tailored to both product people and engineers! https://youtu.be/_fvk_Qa5OsM Thank you PyCon TH team!
Looking for a flat for rent, with LLMs
Code generators replace mindless coding with productivity; a pure function that produces predictable code, given a (set of) input(s). Generating boilerplate classes or templates — a common use case for Codegen. Use-case: Generating Classes We will be...
Your application probably does not need to execute some code each time it is used. We have been caching for decades; reducing database queries, using key-value stores, OPcode caching and the list runs on. Things become overwhelming. I believe often we can find the best answers in simplicity; complexity should not be introduced where a simple solution can help.
When your application bootstraps, build combinations of all the possible states that might result in different content among the views.
Generate the actual content for all those combinations generated above.
Store the generated content as static files, serve with nginx.
Proxy the non-static requests directly to the application.
Depending on the design of your application, you probably will see a considerable number of requests getting served by nginx directly without any involvement of your backend application.
You probably cannot staticify everything in your application. You have to choose what needs to stay static and what needs to remain dynamic. A simple rule of thumb is volatility.
If new records/data/rows get added frequently, that's a big no-no for staticifying it.
If the number of possible values is very high for any parameter you wish to base content generation upon, that is also a big no-no.
You cannot use static sites for validation and processing of a form.
Imagine you will generate static content based on a user's account type and some other parameters.
account_type (free, basic, premium, gold, platinum)
billing_type (wirecard, credit card, nets, ezlink)
is_beta_user (yes, no)
So, you ran into 5 x 4 x 2 = 40 possible states. So the math is easy. Things can go out proportions unless you are careful! So carefully generate and manage the combinations.
Simply think of this passing the context variables to a templating engine for it to render an output. That's it. You got it.
One approach I personally prefer is to create directories for each possible value combination. So it would look like,
free/index.html
free/upgrade.html
premium/index.html
premium/wirecard/billing.html
The application should have a dynamic entrypoint, from where the user is redirected to the appropriate static directory.
I just did a quick write-up, not sure if this will spark anyone's interest. If you want to know more about this, please leave a comment so that I can get to know that I have to write another followup!
(I used this approach to build a USSD service, where authentication doesn't need to be performed by the application. So yeah that's why it was practical!)