why is sftp recommended over ftp?
sftp encrypts data (including usernames and passwords) in transit, preventing credentials from being exposed to network sniffers.
Video Summary
Choose hosting with secure access (SFTP) and the features you need; shared hosting can hide resource limits.
Scale vertically (bigger machines) or horizontally (more machines); horizontal scaling plus load balancers is more sustainable.
Session state and database writes complicate load-balanced architectures — use shared storage, sticky sessions, or centralized session stores.
Cache aggressively (MySQL query cache, memcached, static HTML) to reduce DB and CPU load; manage finite RAM with eviction policies.
Database replication (master-slave, master-master) and redundant load balancers/switches increase availability but add complexity.
sftp encrypts data (including usernames and passwords) in transit, preventing credentials from being exposed to network sniffers.
shared hosting places many users on one OS instance competing for resources; a vps gives you an isolated virtual machine slice with dedicated OS-level control and reserved resources.
use horizontal scaling when a single machine reaches practical limits or cost/availability trade-offs favor many cheaper servers rather than one ever-larger server.
sticky sessions route a user to the same backend server; shared session stores (file server, database, or memcached) let any server access session data, avoiding per-server session loss.
memcached caches frequently read data in RAM as key-value pairs, reducing repeated database queries and improving response times; it requires eviction policies because RAM is finite.
master-slave sends writes to one primary and distributes reads to slaves (simpler but single-write point); master-master allows writes on multiple servers for better redundancy but adds replication complexity.
“Tonight we talk about scalability.”
The lecture focuses on the concept of scalability in web development, particularly how applications can deploy on multiple servers beyond just a personal machine.
Students are encouraged to revisit topics from earlier in the semester to better understand how to handle larger scales of operation.
“What kinds of features should you be looking for or expecting minimally in any web hosting company?”
It is important to research web hosting companies and understand the essential features they should offer.
Examples of popular hosting services are mentioned, although they are not offered as direct recommendations.
Students should be wary that some hosting services may lack important features despite their advertisements.
“SFTP is secure.”
The Secure File Transfer Protocol (SFTP) is highlighted as a necessary security measure compared to the older File Transfer Protocol (FTP), which sends data, including usernames and passwords, in clear text.
The encryption provided by SFTP ensures that sensitive data is kept secure from potential eavesdroppers.
“A VPS is like your own machine running on a box.”
Shared hosting may be insufficient for serious applications because of limited resources shared among many users on a single server.
A Virtual Private Server (VPS) offers dedicated resources, allowing for smoother operation as it simulates multiple virtual servers on one physical machine.
While VPS is more secure from other users, it remains vulnerable to the hosting company's access.
“In order to get these additional features or properties in a VPS, you generally pay more.”
VPS options commonly start at a higher price point than basic shared hosting, sometimes beginning at $50 or more per month.
Companies that provide VPS typically offer features that enhance resource availability and performance.
“You can automate the process of spawning more web servers.”
Services like Amazon EC2 allow companies to automatically manage resources in response to increases in web traffic.
This flexibility supports the management of sudden popularity and can automate scaling down when traffic subsides, optimizing resource use efficiently.
“Vertical scaling means upgrading one machine.”
Vertical scaling involves enhancing a single server's capabilities, such as adding more RAM or processors.
However, there are limits to how much a single machine can be upgraded, necessitating a look at alternative strategies as resource demands grow.
It is essential to recognize that there's a ceiling associated with vertical scaling, prompting developers to consider smarter, scalable solutions in the long term.
"Machines today possess more computational capabilities, allowing them to handle multiple requests in parallel, which we couldn't do with single-core processors."
In the past, computing resources were limited to single-core CPUs, which could only execute one task at a time. Modern multi-core processors enable systems to process several web requests simultaneously, improving scalability significantly.
Operating systems adeptly schedule tasks to give the impression of simultaneous processing, even when operations are executed sequentially. The actual performance bottlenecks become less noticeable due to the speed of today's processors.
With advancements such as quad-core processors, servers can handle multiple requests concurrently, leading to the capability of managing up to four or more web requests in true parallel processing.
"While modern hardware offers tremendous power, many typical tasks don’t require cutting-edge technology."
Though advancements in hardware provide users with more resources, many individuals do not utilize the full capabilities of their devices. Basic tasks such as checking email could easily be managed by machines with far fewer computational resources.
Software bloat in modern operating systems and applications accounts for increased resource usage, yet several users still find their needs met with older technology.
The conversation includes details on hard drive technologies, explaining the differences between Parallel ATA, SATA, and SAS drives. SAS drives, spinning at 15,000 RPM compared to 7,200 RPM for SATA, deliver enhanced performance at a higher cost.
SSDs are mentioned as the fastest storage options available today, outperforming mechanical drives due to their lack of moving parts, despite their higher price and lower storage capacities.
"Accepting potential system ceilings necessitates architectural choices that avoid reliance on top-tier hardware alone."
Horizontal scaling involves building systems with multiple cheaper machines rather than relying on one expensive, high-performance server. This approach encourages utilizing older servers to maintain cost efficiency while still accommodating increased demand.
As systems expand, the importance of effectively distributing web traffic across servers becomes crucial. The video touches on the implementation of load balancers to manage incoming requests efficiently.
Instead of directing all traffic to one server, introducing load balancers allows for the distribution of requests across numerous back-end servers, preventing overloading and ensuring system resilience.
Emphasizing the benefits of private IP addresses, load balancers can shield backend servers from direct public access while simplifying IP management, which has become increasingly challenging due to the scarcity of IPv4 addresses.
"The load balancer decides to send the request to the least busy server in the interest of optimizing performance."
Load balancing involves directing requests to servers based on their available CPU cycles, enhancing overall system performance.
The load balancer evaluates which server to send a request to by checking the current load and selecting the server with the least traffic.
Once a server is identified as capable of handling the request, it communicates within the local server network to respond to the client.
A common mechanism for this communication is TCP/IP, used to transmit packets back and forth between the client and server.
"Load refers to how busy a server is, and one approach is to have dedicated servers for different types of content."
A simpler alternative to dynamic load balancing is having dedicated servers for specific types of content, such as HTML files or images.
This method allows the load balancer to handle requests based on specific URL patterns, directing HTML requests to one server and image requests to another.
The downside of requiring all servers to have identical content is the increase in disk space usage, but this redundancy supports horizontal scalability.
"Instead of returning the IP address of the load balancer, the DNS server can return the IP address of different servers in a round-robin fashion."
DNS can be configured to implement simple load balancing by returning different IP addresses for each request to the same hostname, a technique known as round-robin DNS.
This approach requires configuring the DNS server with multiple IP addresses for a single host, and it allows for straightforward distribution of incoming traffic.
While round-robin DNS is easy to implement and avoids complex communication with backend servers, it may lead to uneven load distribution across servers.
"One server could receive all the hefty requests, while others handle lighter workloads due to the random nature of round-robin DNS."
A significant drawback of round-robin load balancing is that it does not consider the actual workload of each server, potentially causing one server to handle all the heavy requests while others get lighter ones.
The use of caching by browsers or operating systems can compound this issue, as cached DNS responses prevent uniform distribution of traffic across all servers.
If a user continually makes requests to a specific server, while other users are directed to different servers, this disparity can create an imbalance in server load.
"There's typically expiration times, TTLs, associated with an answer from a DNS server."
Time-to-live (TTL) values dictate how long a DNS record remains valid and can range from minutes to days, depending on the DNS server's configuration.
As a power user, your connection may persist for a while until the TTL expires, leading to potential reassignment to different servers.
Using DNS-based round-robin for load balancing may be simple, but it introduces challenges that more sophisticated load balancers can mitigate.
"Sessions have just broken in PHP if our backend servers are PHP-based websites and they are using the session super global."
Load balancing can disrupt session management because sessions are often tied to specific servers, which store them as serialized text files.
If a user is switched from one server to another, they may face login prompts or data discrepancies since the new server doesn't recognize their session.
On an e-commerce site, this can result in users adding different items to their carts across servers, creating a chaotic shopping experience during checkout.
"We could instead have a file server that is connected to all of the servers so that anytime they store session data, they store it there instead of on their own hard drive."
One solution involves implementing a shared session storage system that all servers can access, which would help maintain state across load-balanced servers.
Integrating session management into a load balancer could introduce a single point of failure; if that server goes down, all session data could be lost, resulting in significant downtime.
Introducing RAID technology could enhance data redundancy and reliability, allowing multiple hard drives to serve shared session data across different servers without compromising uptime.
"RAID zero offers high performance, while RAID one provides data redundancy by mirroring data across two drives."
RAID configurations enhance data storage solutions by balancing performance and data safety.
RAID zero utilizes striping to enhance performance, but lacks redundancy. In contrast, RAID one involves mirroring, ensuring data remains intact if one drive fails.
The process of writing a file involves saving it to both drives simultaneously, introducing a performance overhead but greatly enhancing data security.
If one drive in a RAID one setup fails, users can replace it without data loss, benefiting from the array's ability to rebuild itself automatically.
RAID 10 combines RAID zero's performance benefits with RAID one’s redundancy, though it requires more drives and comes at a higher cost.
"RAID five offers better capacity efficiency, using fewer drives for redundancy compared to RAID one."
RAID 5 offers a middle ground between performance and redundancy, allowing for greater storage capacity while sacrificing just one drive for data protection.
For example, if you use five 1TB drives, you gain four terabytes of usable space while maintaining redundancy.
RAID 6 enhances this by allowing two drives to fail without losing data, though it requires an additional drive for redundancy.
These RAID options reduce the likelihood of data loss and can decrease downtime, making them highly beneficial for both personal and server setups.
"For data centers, it's common to have multiple hard drives and power supplies to enhance redundancy and reliability."
Redundant configurations in servers help maintain uptime and protect against data loss.
Systems often include multiple power supplies to ensure continued operation if one fails, providing a robust solution for critical data centers.
If a power supply fails, the machine can keep running while the faulty unit is replaced, illustrating the effectiveness of redundant hardware setups.
These technologies play a crucial role in institutional settings, offering high levels of reliability that go beyond typical home computer setups.
"While redundancy helps, shared storage can still present a single point of failure that needs addressing."
Utilizing shared storage simplifies the management of file systems across multiple servers but introduces vulnerabilities if that single server goes down.
Technologies like fiber channel and iSCSI enable faster and more efficient data sharing across networked systems, although they come with their own costs and complexities.
MySQL is a viable alternative for storing session data, allowing session information to persist even if a server encounters issues.
Solutions like Network File System (NFS) can facilitate shared storage, but the real challenge remains in preventing downtime from server failures.
"Implementing a load balancer can be a complex and costly endeavor, often ranging in the thousands of dollars."
Load balancers distribute network traffic efficiently across multiple servers, enhancing application reliability and performance.
Today, various options exist for load balancing, including cloud-based solutions like Amazon's Elastic Load Balancer and software like HAProxy and Linux Virtual Server.
Despite the rise of software solutions, enterprise-level hardware load balancers can be extremely expensive, sometimes exceeding $100,000.
The investment in such technologies is motivated by the need for high availability, as a single point of failure can significantly impact service uptime and reliability.
"We have one other solution to the problem of sticky sessions, meaning that when you visit a website multiple times, your session is somehow preserved even if there are multiple backend servers."
Sticky sessions help maintain user sessions across multiple visits, ensuring users return to the same backend server.
Shared storage was considered as a solution, where session data could be stored centrally to provide redundancy; however, the implementation posed challenges.
A suggestion was made that cookies could be used to store server identification, allowing users to return to the same server by including their session ID in the cookie.
"Storing everything in cookies is probably bad because it can violate privacy and cookies typically have a finite size."
While cookies can be useful for storing session identifiers, there are significant privacy concerns when personal information is stored directly in cookies.
The size limitation of cookies can cause issues in contexts where too much data is attempted to be stored.
A proposal was made to store a random identifier in the cookie, which the load balancer would associate with the relevant backend server, thus providing a balance between functionality and user privacy.
"PHP and interpreted languages tend to get a bad rap for performance because they tend not to be as high performing as compiled languages."
PHP can be optimized through the use of acceleration techniques, allowing for quicker execution of scripts by keeping compiled operation codes cached.
Whenever a PHP file is accessed, it gets interpreted and compiled; however, without caching, this process occurs repeatedly for each request.
Using PHP accelerators can significantly boost performance by preventing the repeated compilation of the same PHP files, enabling the server to handle more requests concurrently.
"Caching can be implemented in the context of dynamic websites in a few different ways."
Caching is not just beneficial for performance; it can also mitigate some issues tied to data retrieval and redundancy.
Different methods of caching can be employed, such as through HTML, MySQL, and even mechanisms like Memcached, which help enhance the efficiency of dynamic websites.
An example of a website employing caching strategies is Craigslist, which saves generated HTML files to avoid repeated regenerations, highlighting a practical approach to managing dynamic content.
"Web servers like Apache are really fast at delivering raw static content, such as a GIF, JPEG, or HTML file."
The effectiveness of web servers in handling static content is highlighted, as they can quickly respond to requests with minimal processing overhead.
While serving static content comes with performance benefits, it is essential to recognize the trade-offs involved, including increased disk space usage and redundancy.
As data is stored on disk, there is a potential downside in that changes to web pages become cumbersome, especially in platforms that rely solely on static HTML files.
"There’s always a gotcha; with thousands of files, there’s redundancy in the basic stuff like the same HTML tag in every single page."
Static HTML pages tend to have significant redundancy, as common elements such as headers, footers, and scripts are repeated across multiple pages.
This repetition can complicate maintenance tasks like altering aesthetics or structural changes since edits must be applied to each file individually, which is not efficient.
"You get much better performance from serving up the static content, but the price you pay is more disk space."
Utilizing file-based caching allows websites to load faster by serving static content efficiently, but it can increase the storage needs on the server.
The trade-off between performance and disk space should be evaluated; sometimes, investing in larger storage options may resolve space concerns more effectively than restructuring how content is served.
"MySQL provides caching for identically executed queries for more efficient performance."
Query caching in MySQL allows for faster retrieval of data by storing results of previous queries, reducing the need for repeated heavy database calls.
Enabling query caching is straightforward and can significantly improve performance for sites with frequent similar queries.
"Memcache is a memory cache that stores data in RAM for quicker access compared to traditional databases."
Memcached operates as a key-value store, allowing rapid retrieval of user data by caching it in memory rather than constantly querying a database, which can be a slow operation.
This system improves performance by minimizing the dependence on disk access, utilizing RAM's speed for frequently accessed data.
"You first connect to the memcached server, similar to how you would connect to MySQL."
Integrating Memcached with PHP requires establishing a connection to the caching server, allowing the application to utilize fast data retrieval through cached key-value pairs.
If the desired user data is not found in the cache, the application will need to query the database and subsequently cache that retrieved data for future quick access.
"Caches are finite because RAM is limited."
It is crucial to recognize that while caching greatly enhances performance, memory is limited, necessitating careful management of what data is stored.
Implementing effective strategies to prioritize which data to cache can ensure that the most frequently accessed information remains available, optimizing overall application efficiency.
"Eventually, the cache could get so big you can't keep it on the machine."
As caches grow, they may exceed the available RAM or disk space, necessitating strategies to manage memory effectively.
A common solution is implementing garbage collection, which removes less-used objects from memory to make room for new data.
For instance, objects can be expired based on their last usage. If a user object hasn’t been accessed for a while, it can be removed to free up memory for new entries.
This first-in, first-out (FIFO) approach helps optimize memory utilization, ensuring that frequently accessed objects remain available.
"If you get a cache hit, I could somehow execute another cache function that just touches the user object."
Maintaining user profiles in a cache system is vital, especially for power users who log in frequently.
Each time a cached user is accessed, the cache can update the access timestamp to reflect its recent use. This helps keep active users in the cache longer.
Effective caching is crucial for platforms like Facebook, which still tend to generate more reads than writes, even amidst updates and posts.
"In MySQL, different storage engines affect performance and capabilities."
MySQL supports various storage engines, each with unique characteristics that influence how data is managed.
For instance, the InnoDB engine supports transactions while MyISAM utilizes full table locks, a method that can affect performance.
Additionally, memory engines store tables strictly in RAM, retaining high-speed access at the cost of data persistence during power loss, making them useful for temporary caches.
"You generally have a master database which is where you read data from and write data to."
Database replication creates identical copies of data across one master and several slave databases, ensuring redundancy.
This setup allows for quick recovery in case of failure. If the master database fails, one of the slaves can be promoted to take its place with minimal downtime.
Load balancing across slave databases can also help manage query traffic, optimizing performance during high-demand periods, particularly useful in systems like Facebook, which primarily generate read queries.
"For a read-heavy website like Facebook, you could write your code so that any select statements go to databases two, three, or four, while inserts, updates, or deletes go to server one."
In a topology designed for read-heavy traffic, multiple database servers can be utilized, allowing read queries to be distributed among several databases, enhancing performance.
The architecture proposes that all write operations are funneled to a primary server, while read operations are balanced across several secondary servers.
This design means that even if a primary server is temporarily offline for maintenance, users can still browse and access profiles without interruption. However, there's a risk of downtimes in the functionality for status updates since they rely on the single master server.
"We still have a single point of failure here for writes, as we have to promote a slave into a master."
While having a primary and multiple secondary servers greatly enhances read requests, it introduces a dependency on the master server for all write actions.
If the primary server fails, there is a need to promote a secondary (or slave) server to maintain functionality for writes, which can lead to service interruptions and affect uptime.
To tackle this, a master-master configuration can be introduced, allowing for writes on both servers which enhances reliability and load balancing.
"With a master-master setup, you could write to either server, which replicates the queries to the other."
In a master-master setup, there are two primary servers, allowing both to handle write requests, thus reducing the risk of downtime.
If one server goes offline, the other remains operational, ensuring continued access and functionality.
Implementing redundancy through code can ensure the application checks for server availability, switching connections seamlessly between the servers if one fails.
"We need to ensure we don't rely on a single load balancer, as that can create a bottleneck in our architecture."
The architecture requires a load balancer to distribute requests efficiently across multiple servers. However, relying on a single load balancer poses a significant risk of becoming a single point of failure.
To mitigate this risk, implementing multiple load balancers in an active-active configuration allows both to process requests simultaneously.
This configuration increases reliability, ensuring that if one load balancer fails, the other can continue to manage incoming requests without impacting user experience.
"Partitioning helps scale the architecture horizontally by distributing users across multiple servers based on specific criteria."
Facebook initially employed a partitioning strategy, allocating different servers for different schools, facilitating management of distinct user groups.
While effective in scaling, partitioning can complicate interactions between users across different databases, as specific features may be restricted within individual partitions.
A simple partitioning approach can distribute users based on their last names, allowing better resource management and redundancy while maintaining swift access based on user origin.
"You can actually take into account what someone's name is and then send them to this particular server."
Load balancing can be optimized by utilizing high-level user information rather than solely relying on simple methods like round robin.
This process involves partitioning users effectively across multiple servers based on identifiable attributes, enhancing overall resource allocation.
"High availability refers to some kind of relationship between a pair or more of servers that are somehow checking each other's heartbeats."
High availability (HA) systems ensure that if one server fails, another can seamlessly take over the workload.
This is achieved through regular heartbeat checks between servers, allowing for immediate action to maintain service continuity.
"Use a load balancer and store all the sessions in one place."
When setting up a network, implementing sticky sessions is crucial for maintaining user sessions across multiple web servers.
A load balancer can effectively manage sticky sessions by remembering which server a user is connected to, using cookies to track session information.
"If Alice just happens to end up on server one and she updates her profile...it’s going to persist on this database and that's fine."
Storing the database on the same servers as the web application can lead to inconsistencies, especially when users interact with different servers.
To address this, databases should be externalized to allow for consistent access regardless of which server the user connects to.
"The single point of failure again."
Externalizing the database introduces the risk of a single point of failure, where losing the database could cripple the entire system.
Implementing multiple master databases can help alleviate this risk, but it requires thoughtful consideration regarding their interconnectedness.
"Now my load balancing has to be done in code."
When connecting load balancers to multiple databases, developers must implement code that recognizes and responds to which database is operational, complicating system architecture.
This complexity heightens the chance for errors as developers must constantly update the logic in the code when the infrastructure changes.
"You would do this with switches or some kind of ethernet cables."
To eliminate singular points of failure in load balancing, redundant load balancers should be integrated into the system architecture.
Utilizing a central switching mechanism can help manage these load balancers and facilitate robust connections among them, thereby enhancing overall system reliability.
"The right way to ensure redundancy is to have at least two switches for your servers."
Network redundancy involves implementing multiple pathways for data to travel, ensuring there is a backup if one fails.
Typically, servers will have at least two Ethernet jacks, each connected to a different switch.
Care must be taken to avoid creating loops in the network, which can cause traffic deadlocks.
Having redundancy not only improves scalability but also increases the likelihood of uptime and resilience against failures.
"If the building burns down, that's more extreme than I had in mind, but it happens."
A data center can face extreme situations such as a fire, power outages, or network disconnections, which can dramatically affect uptime.
These incidents highlight misconceptions about cloud computing, particularly regarding its reliability during outages.
Understanding that cloud services often mean outsourcing resources like power and security can mitigate misunderstandings about their failure when incidents occur.
"Amazon offers Availability Zones, which are separate buildings with independent power and networking."
Amazon Web Services (AWS) provides Availability Zones to help mitigate the risks of single points of failure by hosting services in multiple isolated locations.
These zones are designed in a way that one zone going offline should not affect others, though outages can still occur simultaneously across multiple zones.
AWS operates various data centers worldwide, enhancing geographic redundancy.
"You can use DNS for load balancing, allowing for geography-based requests."
Load balancing can be achieved at different levels, including DNS-based strategies that direct users to the nearest server location.
This practice helps to distribute the load more efficiently across various data centers globally.
However, challenges remain in ensuring session persistence for users, as they should interact with the same instance throughout their session.
"You need to allow specific traffic types for your web servers to function securely."
When hosting a website, it's crucial to determine which types of traffic are permitted through your firewall to maintain security while allowing functionality.
Common practices include allowing TCP connections on ports 80 (HTTP) and 443 (HTTPS).
However, blocking all other ports can hinder legitimate access methods such as SSH for server management, which may require configuring additional open ports.
"Offloading SSL termination to load balancers simplifies server configurations."
SSL termination at load balancers allows for encrypted traffic from the internet to be decrypted and sent as regular HTTP within the data center.
This setup reduces the computational burden on web servers, as they don’t need to handle SSL processing.
Utilizing load balancers in this way can lead to cost savings on web server resources.
"In theory, they are allowed by the firewall to query your database and execute SQL commands."
The discussion starts by identifying that SQL queries, such as select, insert, and delete, are generally executed over TCP port 3306, which is the default for MySQL. Understanding these details is crucial when configuring firewall rules for database access.
It’s important to consider the implications of firewall configurations. The speaker emphasizes the need for a proper setup to prevent unnecessary access to the database, thereby ensuring security.
The principle of least privilege is underscored: only open the necessary ports that users need to access without inviting potential vulnerabilities. For instance, keeping port 3306 open can allow unauthorized SQL queries, which can compromise database security.
The caution is expressed that if a server is compromised, limiting its communication capabilities to only MySQL connections can help contain the threat. The idea is to restrict the damage the attacker could do by only allowing access to a defined set of services.
The speaker notes that while the class has not delved deeply into firewall management, it's essential to understand that providing minimal access is a best practice in securing a network and its databases.
"As soon as you have the happy problem of having way too many users, lots of new problems arise."
The conversation transitions to highlight the complications that arise in multi-user environments, particularly regarding scalability and software management.
The complexity of managing security increases with the number of users, necessitating more refined strategies to monitor and control access.
The audience is reminded that while the focus in the course has primarily been on software aspects, understanding the hardware and networking components is equally vital for ensuring system security and performance.
The mention of feedback for the final project suggests that the course also emphasizes continuous improvement and adaptation to changing circumstances as a crucial skill for developers.