django Architecture - Connection Management

  Рет қаралды 52,531

Hussein Nasser

Hussein Nasser

Күн бұрын

Пікірлер: 85
@phantomrex1348
@phantomrex1348 2 жыл бұрын
I feel like Hussain is one of the only KZbinrs that actually puts hours into his work. Keep up the good job
@muhammadahsan5676
@muhammadahsan5676 2 жыл бұрын
I agree
@MartinsTalbergs
@MartinsTalbergs 2 жыл бұрын
Feel ya, men must do work to be men
@luuc
@luuc 2 жыл бұрын
'hours' is peanuts when it comes to content creation lol
@fadious_padious2711
@fadious_padious2711 2 жыл бұрын
I feel like he is also one of the few tech KZbinrs who knows his stuff inside and out. There are definitely others but the majority of tech channels are new grads reading snippets out of the documentation.
@hxxzxtf
@hxxzxtf 9 ай бұрын
🎯 Key Takeaways for quick navigation: 00:00 *🐍 Django simplifies database connections by using objects instead of writing SQL queries.* 01:22 *💻 HTTP requests to Django connect to the database to execute queries and build responses.* 02:56 *📊 Django establishes database connections upon receiving requests, minimizing connection overhead.* 05:37 *🔄 Persistent connections are favored in modern architectures to minimize connection overhead.* 06:19 *🛠️ Django allows configuring persistent connections with 'connection max age=none' for efficient handling.* 07:00 *📄 Django follows a one connection per thread model, limiting connections to the number of threads.* 09:35 *⛔ Django's single connection per thread model can lead to blocking when multiple clients request database connections simultaneously.* 11:57 *🔀 Scaling Django with multiple threads can improve performance but should align with CPU core recommendations to avoid context switching overhead.* Made with HARPA AI
@samydriss5223
@samydriss5223 2 жыл бұрын
Hussein, I love and appreciate all the content you put out. You truly are a rare breed of teacher. I can't express my gratitude enough as well as how much you have taught and have helped me throughout my career. I always learn something new when I watch your videos, take your courses, listen to your podcasts or read your articles. You have this great ability to go very deep into the technology stack without confusing people. Really, not all heroes wear capes. Also, are we seeing a teaser for a Udemy course here? 👀 Salam from 🇩🇿
@imanmokwena1593
@imanmokwena1593 6 ай бұрын
Thanks to watching this guy last year, I now understand everything in this video lol. Last year, it felt so foreign. Even before he mentioned cores, i already knew where he was heading. Hussein is an excellent teacher.
@aashayamballi
@aashayamballi 2 жыл бұрын
Django is ❤ Thank you Hussein for talking about Django and covering about this topic...
@isurucumaranathunga
@isurucumaranathunga Жыл бұрын
Hussain I don't hv words to say, these stuff are absolutely important and these are the actual engineering stuff. I love this content and really appreciate your effort on these videos. There stuff are really important for everyone specially for fresh graduates like me. Again thank you so much. Watching and noting down your videos is my new hobby. Thanks again.
@icns01
@icns01 4 ай бұрын
Only a few minutes in, I can tell this is a good instructor...Good clear explanations backed by nice diagrams to further illustrate the concepts...Subscribed..👍
@abiiranathan
@abiiranathan 2 жыл бұрын
I believe the problem is not with Django per say but python's threading model. Yes you guessed right, the GIL. Also to avoid data races, Django has to execute the queries synchronously. Even using async frameworks like django channel, you must wrap your async coroutines with synchronous helpers. Hello GIL
@pleli
@pleli 2 жыл бұрын
I'm guessing multithearding in python deserve a video of its own. Django usually used behind a wsgi server (nginx, gunicorn etc.) In a way you will have multiple processes with single thread on each process.
@SsaliJonathan
@SsaliJonathan 2 жыл бұрын
Thanks for making this video Hussein.
@MakeItStik
@MakeItStik 2 жыл бұрын
Really informative video. Make more like these !! We love it.
@matrixtoogood5601
@matrixtoogood5601 2 жыл бұрын
Thank you for this amazing video! I would love to see a video on frontend listening models.
@LOLxUnique
@LOLxUnique 2 жыл бұрын
Great video from one Hussein to another
@vfryhn2
@vfryhn2 2 жыл бұрын
Hussein could you please explain how WSGI servers work or why are they necessary for production with the python frameworks and not with other languages like node js or go? I just can't understand why they need that intermediate layer between the python server and the clients
@MaulikParmar210
@MaulikParmar210 2 жыл бұрын
Your inbuilt http server isn't a process manager, what wsgi does is it taps into process management and separates application execution. Allows separating environments, application context and much more stuff that is required to invoke application efficiently and securely while keeping resource usage minimum. Implementation may vary depending on what server you are using but simple idea is, it's webservers responsibility to sandbox request response lifecycle and wsgi provides that barebones for any application and allows it to be build on top of already solved problems when you are writing web applications. This is same as (but not equal to i.e. similar to) using express in node, php-fpm, tomcat / websphere or any other application server, they are server appa helping in management and hosting of application itself while keeping them isolated from host system in one wya or other and providing specific standardised API at your application layer where you actually write business logic.
@vfryhn2
@vfryhn2 2 жыл бұрын
@@MaulikParmar210 thank you!
@Ysh.CS_guy
@Ysh.CS_guy 2 жыл бұрын
Great video 📹 👍 👏
@Kostas_Panagias
@Kostas_Panagias 11 ай бұрын
Great content! Very well explained! Thanks for all the effort you put into this.
@nucleusnode23
@nucleusnode23 4 ай бұрын
really good man!
@_overide
@_overide 2 жыл бұрын
As always, great video. Thanks you so much, learned few new things!
@ujjwalbansal5649
@ujjwalbansal5649 Жыл бұрын
Awsome content.
@mlsandreas
@mlsandreas 2 жыл бұрын
Thank you sir!! Awesome video!!
@dipjul
@dipjul 2 жыл бұрын
Very interesting! Can you please make a video on spring/springboot backend architecture?
@alexsmart2612
@alexsmart2612 2 жыл бұрын
Hi Hussein, I don't quite agree with your discussion regarding context-switching near the end of the video. Your typical web-server is IO bound and like you explained the worker threads are just mostly sitting idly waiting for a response from the database. If that is the case, why would context-switching be a significant concern? Even if you have a hundred threads, the context switch only happens when there is an actual response from the db server, right? And when it does happen, the cost of the context switch (< 10 μs) is insignificant compared to typical db response times (at least a few milliseconds).
@syedazzamzafar596
@syedazzamzafar596 2 жыл бұрын
I am beginner django developer. What course from you should I take first to improve my backend knowledge?
@malekalhourani5930
@malekalhourani5930 2 жыл бұрын
Hi Hussein, thanks for such content, it is really helpful and help me to evolve. I feel like using your old way of explaining stuff (using a PowerPoint presentation) is much easier to follow and make the topic you are trying to explain much simpler, I hope you return back to use it again, Thanks.
@illichoskypiotr
@illichoskypiotr 2 жыл бұрын
Got confused. Isn't WSGI spinning a new forked subprocess every time a new request arrives? How does that relates with this one connection per thread?
@NavidRashik
@NavidRashik 2 жыл бұрын
On another note is that from 4.1 it support async orm and views so yah async is supported there as well
@andresgutierrez1804
@andresgutierrez1804 2 жыл бұрын
What about asgi with one thread how the Django will handle the transactions?
@arcstur
@arcstur 2 жыл бұрын
Awesome video!
@frozeneye100
@frozeneye100 2 жыл бұрын
Lol. Love way you say the bad kid dB. Really the orm. I am beginner Dev level but crap. I am forcing myself to do ORM way coz want to learn but just SQL seems so much easier than rubbing ORM into compliance. Really ORM is the hardest and doing Django way. But at times the SQL is way quicker than orm... But yeah learning is cool and your vids even better.
@Tekecthegoat
@Tekecthegoat 2 жыл бұрын
so a single thread only handles on cuncurrent user? Am I missing something?
@mustaphab32
@mustaphab32 2 жыл бұрын
Great stuff! it think it worthes mentioning that ORM only lately started being async in a very recent version, which means the thread will keep the request waiting and any other calculation as-well! we d love to see how to do parallel processing in python and especially Js and Python!
@MukulAsija
@MukulAsija Ай бұрын
Thank you
@rizwanfirdous
@rizwanfirdous 2 жыл бұрын
I highly appreciate your video and the hardwork behind it. One request to you could you please make a same kind of video for hibernate and tomcat. Please...
@noriking1467
@noriking1467 2 жыл бұрын
Is it possible to do spring boot architecture and how project reactor works ? love the storytelling here !
@adityajoardar578
@adityajoardar578 2 жыл бұрын
I think this is one of the major drawbacks of doing backend processing in django, because if we have to update databases continuously in a background thread, that means we can't use persistent connection as it will keep one of the connections in idle state always
@bibekjoshi3522
@bibekjoshi3522 2 жыл бұрын
Was looking at something similar and notification for this video came up
@CamaradaArdi
@CamaradaArdi Жыл бұрын
This is my Well actually comment: you have two CPU threads per physical core. Also it's the kernel who does the context switching, not the CPU Also a thread that's waiting for network can safely be idle. As long as it's not doing work. The kernel is smart enough to give it a lower priority. Since read()ing a socket blocks (unless you're doing epoll) you can safely have 100 threads waiting for responses without a significant performance degradation. The problem will be of course if all of those threads are doing work at the same time, where you're absolutely correct.
@yashvarshney8651
@yashvarshney8651 8 ай бұрын
yep it is the OS's work to schedule and context switch processes
@DanielTateNZ
@DanielTateNZ 2 жыл бұрын
Very interesting, I would be interested to hear your opinions on Laravel a popular PHP framework.
@TheLolEdits
@TheLolEdits 2 жыл бұрын
fast api next?!
@riadalimammedov7209
@riadalimammedov7209 Жыл бұрын
Hello Hussein,please record fastApi Architecture analysis.
@MohdImran-uq5iv
@MohdImran-uq5iv 2 жыл бұрын
Thank you Hussain.. I am waiting for your 5th udemy course 😅
@mehdi-vl5nn
@mehdi-vl5nn 2 жыл бұрын
what about async orm (django4+)?
@justvebsthings
@justvebsthings 20 күн бұрын
I have django project and now I hit multiple requests but its fails its only process one request at a time help me to process multiple requests in django parallel processing
@brightlight1485
@brightlight1485 Ай бұрын
what is role of Gunicorn?you did not mention
@zeyadmoustafakamal
@zeyadmoustafakamal 7 ай бұрын
Well I am here from 2024 and I heard that in python 3.13 you might don't have to use the GIL if you precompiled the library. So will this affect django or not ?? and also can we just use some rust code to improve this. by (for example) rewrite the template engine and maybe the ORM in rust ??
@nandusraj7801
@nandusraj7801 7 күн бұрын
Hi Hussein You said the database connection is only established when the request is received and not on application startup if I understand right. Isn't this the default behavior for most frameworks? You only establish a connection when it tries to do a database IO right?
@holthuizenoemoet591
@holthuizenoemoet591 2 жыл бұрын
I would love to see a video on a good multi client per thread model
@fartzy
@fartzy 2 жыл бұрын
So is it not good to use multiple threads? Even though there is context switching wouldn’t still go much faster than blocking I/o? Isn’t that why it exists? GIL or not?
@101kawsar
@101kawsar 2 жыл бұрын
Thank you 🥺❤️
@9899722801
@9899722801 Жыл бұрын
Hussein, Can we do data replication in django? I am very confused about it. Some says yes, some say it cant be
@swapniljena8684
@swapniljena8684 2 жыл бұрын
I'm going to post this here as well as on Stackoverflow. So here it goes: I am running Django app using the WSGI server (gunicorn) on Linux. I am using the local memory for caching inside the application. I am using 3 workers (workers are altogether different forked processes that shared different memory spaces) and multi-threads using g-event under each worker. As the memory space is the same for each worker I'm safe having one single cache in one worker. But the load to the workers is balanced by the OS kernel so if the workers have different memory space so, the application cache 'set' by one worker can be made a 'get' by another worker or will it turn into an issue. I can solve this using unified caching using Redis or Memcached but wanted to clear this doubt before implementing another new service.
@RajaKhan-dc4vs
@RajaKhan-dc4vs 11 ай бұрын
you actually are optimising reads. By having a cache pool and pluging it in with your application leverages the cache to fetch responses faster. at some extent mongo or mysql also uses a lru buffer to bring in the recent read pages into memory and thus saving a lot of disk reads as ordered. As per your specification you want to do it in the previous hop by putting a cache layer in between your database layer and your api layer. But you always have to trade latency with cost.
@1412-kaito
@1412-kaito Жыл бұрын
So, if in Django there is like 1 client, 1 thread, 1 query, then how does it tackle several (10k like) clients?
@S--xc4rv
@S--xc4rv 2 жыл бұрын
Qns??? I'm downloading something in my laptop from mobile's network so very interesting thing is happening all the time while downloading. That is , whenever in every 2-3 sec there is spam of 1 sec in which the Mobile network speed goes to less than 0 kb . Why is that happening? And and there is no drop-down speed in laptop. It's normal
@Namjoonsbonsai
@Namjoonsbonsai 6 ай бұрын
Can I learn backend without having any knowledge on front-end
@isegofficial
@isegofficial 6 ай бұрын
Lol of course. I know just Django,I download free frontend templates, then chatgpt helps me write js fetch requests to query my backend api endpoints until I starting doing that myself too
@Namjoonsbonsai
@Namjoonsbonsai 6 ай бұрын
@@isegofficial oh Oka. I'm learning django currently. Just started the class for django and I only know basic python by now so I was really scared 😭 I'll learn the other languages once I'm done with this
@Namjoonsbonsai
@Namjoonsbonsai 6 ай бұрын
@@isegofficial also ,is there a possibility of getting job after I have full django knowledge?
@isegofficial
@isegofficial 6 ай бұрын
@@Namjoonsbonsai of course. Don’t let the internet deceive you. Just build stuff. Like 2 good projects and upload on your GitHub and linkdln
@DhavalAhir10
@DhavalAhir10 3 ай бұрын
​@@NamjoonsbonsaiThere is no possibility, nowdays companies expected Fronted, Backend, Docker, Kubernetes, Apache, nginx, FastAPI bla bla bla
@Dinesh-babu
@Dinesh-babu 2 жыл бұрын
Greatly informative like every other video. What do you think about netty and its use cases??
@venkatavineelyalamarthy6958
@venkatavineelyalamarthy6958 2 жыл бұрын
Is this video added in Udemy course as well. ? On another note, I have a question, if Python is not concurrent (can't run multiple threads at the same time due to GIL), how does Django handle concurrent API requests? Does it use multiple processes.
@SB-qm5wg
@SB-qm5wg 2 жыл бұрын
django have sqlite3 api?
@amirhmahmoodi4607
@amirhmahmoodi4607 2 жыл бұрын
Hussein, what does happen if you put PgBouncer into this?
@alexsmart2612
@alexsmart2612 2 жыл бұрын
Nothing happens. You are still limited by the number of threads, and since django only uses one connection per thread, your thread is still going to sit idly by waiting for a response from the db server. (PgBouncer would have helped with the first problem mentioned in the video, that is django by default creating a new connection for each request if django didn't in fact have a setting to enable persistent connections, but does nothing to help with the second one.)
@mikopiko
@mikopiko 2 жыл бұрын
Could you do a similar video but for Rails? Would be hella interesting to compare.
@vishal240993
@vishal240993 11 ай бұрын
Any solution to this or we need to use db proxy like pgboncer ?
@hnasr
@hnasr 11 ай бұрын
correct pgbouncer proxy helps this.
@yashvarshney8651
@yashvarshney8651 8 ай бұрын
use starlette?
@liorbm1
@liorbm1 13 күн бұрын
@@hnasr i think you needed to mention it..
@SachinDolta
@SachinDolta 2 жыл бұрын
Much love
@charank7852
@charank7852 2 жыл бұрын
Hi Hussein, Thanks for sharing quality content. Can we expect a course on LInux OS fundamentals on udemy as u created for networking ? Please reply. Thanks
@Fido1hn
@Fido1hn 7 ай бұрын
had to speed it up to 1.75 to make it to the end. A lot could be said quicker
@tobidegnon4409
@tobidegnon4409 2 жыл бұрын
I'm sot sure but the way you talk about threads here make me feel that you are actually talking about worker process, not threads, each process having it's own memory, I'm I missing something here?
@buildmore9829
@buildmore9829 2 жыл бұрын
You remind me of Firas Zahabi.. related?
@uEisenhower
@uEisenhower 10 ай бұрын
Explaining before you criticise, i get you're making point but I'm learning nothing except disadvantages of django, which isn't the title
@himanshukandpal5585
@himanshukandpal5585 10 ай бұрын
The video did explain the architecture to you.
Pinterest moves to HTTP/3
25:06
Hussein Nasser
Рет қаралды 36 М.
How many kernel system calls do runtimes make?
19:18
Hussein Nasser
Рет қаралды 30 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
Radoslav Georgiev - Django structure for scale and longevity
45:27
EuroPython Conference
Рет қаралды 48 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 293 М.
Frontend and Backends Timeouts
24:40
Hussein Nasser
Рет қаралды 13 М.
Django Interview Questions (Junior Developer)
30:26
Dennis Ivy
Рет қаралды 129 М.
Threads and Connections | The Backend Engineering Show
49:30
Hussein Nasser
Рет қаралды 66 М.
Where http2 hits its limit
13:13
Hussein Nasser
Рет қаралды 9 М.
FastAPI, Flask or Django - Which Should You Use?
9:49
Tech With Tim
Рет қаралды 116 М.
Node.js is a serious thing now… (2023)
8:18
Code With Ryan
Рет қаралды 663 М.
No-Nonsense Backend Engineering Roadmap
10:16
Codebagel
Рет қаралды 256 М.
They made Kafka 80% faster by switching file systems
31:30
Hussein Nasser
Рет қаралды 36 М.