Servers Basic
A web server is just a computer that serves data over a network, typically the Internet.
Servers run software that listens for incoming requests from clients. When a request is received, the server responds with the requested data.
Any server worth its salt can handle many requests at the same time.
- In Go, we do this by spawning a new goroutine for each request. Go's goroutines are a great fit for web servers because they're lighter weight than operating system threads, but still take advantage of multiple cores.
- Go servers are great for performance whether the workload is I/O or CPU-bound
- In JavaScript land, the server is typically single-threaded. That means that a Node.js server can only use one CPU core at a time. It can still handle many requests at once, but it does so by using an async event loop. In essence, this just means that whenever a request that's being processed has to wait on I/O, the server can temporarily process another request until the first's I/O is complete.
- This might sound horribly inefficient, but it's not too bad. Node servers do just fine with the I/O workloads associated with most CRUD apps. You start to run into trouble with this model when you need your server to do CPU-intensive work.
- Node.js work well for I/O-bound tasks, but struggle with CPU-bound tasks
- Generally speaking, Python application code only processes a single request at a time. This means that if a request is being processed, the application won't do anything else until it's finished.
- Python and Django/Flask do just fine with I/O bound tasks, but frankly, no one picks Python for its performance
A fileserver is a kind of simple web server that serves static files from the host machine. Fileservers are often used to serve static assets for a website, things like:
- HTML
- CSS
- JavaScript
- Images
Servers are interesting because they're always running. They run forever, waiting for requests to come in, processing them, sending responses, and then waiting for the next request. If they didn't work this way, websites and apps would be down and unavailable all the time!
WSGI vs ASGI Web Servers
Introduction to API
All Interfaces define ways for us to interact, or communicate with an object, whether that object be physical, or software, and as a user of the interface, we don't need to understand the implementation.
- We don't need to know how it works. We just need to know what we've been allowed to change, or see.
- Interfaces abstract away the implementation.
While the UI, or User Interface is made for the user of the application, API is made for the application programmer to use, and extend in their applications.