Python Flask Interview Questions Part 5

 

Python Flask Interview Questions Part 5

Here you can find the most frequently asked Python Flask Interview Questions (Part 5) by many multi-national companies.

41) Explain database connection in Python Flask?

Flask supports database powered application (RDBS). Such system requires creating a schema, which requires piping the shema.sql file into a sqlite3 command. So you need to install sqlite3 command in order to create or initiate the database in Flask.

Flask allows to request database in three ways,

before_request() : They are called before a request and pass no arguments

after_request() : They are called after a request and pass the response that will be sent to the client

teardown_request(): They are called in situation when exception is raised, and response are not guaranteed.

They are called after the response been constructed. They are not allowed to modify the request, and their values are ignored.

42) You are having multiple Memcache servers running Python, in which one of the memcacher servers fails, and it has your data, will it ever try to get key data from that one failed server?

The data in the failed server won’t get removed, but there is a provision for auto-failure, which you can configure for multiple nodes. Fail-over can be triggered during any kind of socket or Memcached server level errors and not during normal client errors like adding an existing key, etc.

43) Explain how you can minimize the Memcached server outages in your Python Development?

When one instance fails, several of them goes down, this will put a larger load on the database server when lost data is reloaded as the client make a request. To avoid this, if your code has been written to minimize cache stampedes then it will leave a minimal impact

Another way is to bring up an instance of Memcached on a new machine using the lost machines IP address

Code is another option to minimize server outages as it gives you the liberty to change the Memcached server list with minimal work

Setting timeout value is another option that some Memcached clients implement for Memcached server outage. When your Memcached server goes down, the client will keep trying to send a request till the time out limit is reached

44) Explain what is Dogpile effect? How can you prevent this effect?

Dogpile effect is referred to as the event when the cache expires, and websites are hit by the multiple requests made by the client at the same time. This effect can be prevented by using a semaphore lock. In this system when value expires, the first process acquires the lock and starts generating new value.

45) Explain how Memcached should not be used in your Python project?

Memcached common misuse is to use it as a data store, and not as a cache

Never use Memcached as the only source of the information you need to run your application. Data should always be available through another source as well

Memcached is just a key or value store and cannot perform query over the data or iterate over the contents to extract information

Memcached does not offer any form of security either in encryption or authentication

This article contains the most frequently asked Python Flask Interview Questions (Part 5) by many multi-national companies. Subscribe to our YouTube channel for more videos and like the Facebook page for regular updates.

Leave a Comment

Your email address will not be published. Required fields are marked *