Sherif's Tech Blog

Just another guy on the Internet with a keyboard…

Renewable Energy: You Are Being Lied To

It seems today that the world has been blindly led to believe that we are dependent on non-renewable energy, because there simply is no other alternative energy source that can power the world. You’ve been lied to! Since the dawn of the 20th century the western world has emerged out of the dark-ages, so it seems. The United States being the leader in delivering energy to power homes, businesses, and entire cities with non-renewable energy sources such as fossil fuels. The problem with fossil fuels is that they are inefficient, produce byproducts hazardous to our environment, because they are based on explosion energy (combustion). You may have been led to believe that the world is just now emerging out of the dark ages for the first time. That man has seen only primitive civilizations, without advanced technology, without advanced sciences. You’ve most certainly been lied to and you probably never bothered to question it!

The Truth

The truth is the world has enough renewable energy sources to power our planet and light it up like a Christmas tree for many — many — centuries to come. The truth is renewable, clean, and natural energy is far more efficient than any of the fossil fuel based energy we use today. In fact, the truth is we are not the technologically advanced civilization we think ourselves to be. We’ve been taught in school, for many decades now, that ancient civilizations were primitive people, using stone and copper tools, hunting and gathering, and eventually we built up to civilizations that cultivated the land and so began the manufacturing age. As though mankind has been on a linear course of progression for thousands of years and it’s just now that we have discovered science and technology and things ancient civilizations could not possibly have fathomed. As if we are thinking up computers and massive global networks for the very first time in mankind’s history. Evolutionists would have you believe this fits perfectly with their theories and politicians lining their pockets with the fat-checks of money-hungry oil conglomeration can do little more than back such ridiculous notions. Not based on any shared beliefs or ideologies with evolutionists, but strictly based on math.

If the world were to discover that oil and coal are not the greatest source of energy there would be wide-spread downfall of international energy corporations and all of their infrastructure. Many interested parties would take on insufferable losses and their business would surely vanish like the ancient civilizations we no longer see today. I imagine, that if the ancients were still around today they might actually be the ones laughing at us and calling us the primitive ones. Why is it so inconceivable that other ancient civilizations might have discovered the immense benefits and substantial gains from building global long-term infrastructures that would harness and support technological advancements? Is it really so inconceivable that ancient civilizations could have had sciences and technologies just as advanced as ours, if not more? Unfortunately, science can not teach us what could be, just what is. Yet, it is through science that I can show you just how much you have been deceived.

The Advent of Electricity

In order to see where we went wrong with energy, we must first begin our trip more than 120 years ago when electricity was just taking form in the heart of the United States. During the late 1800′s America was just beginning to form infrastructure that was quickly changing the world. The rapid development of the telephone and now electric power plants. This was at a time when Edison was just getting started.

However, most of us only know one half of this story. We tend to have a biased opinion about energy problems today, primarily because we have insufficient information to actually make an informed decision about the subject at hand. We are ill-equipped to formulate opinions, because we lack the analysis of the full story.

In the late 19th century a man named Nikola Tesla began bumping heads with Thomas Edison. Tesla, worked for Edison at the time. Edison wanted to use DC – Direct Current – which was inefficient and proved difficult to supply due to its limitations in transport. Tesla wanted to use AC – Alternating Current – which proved superior to Edison’s Direct Current. A direct current travels in one direction whereas an alternating current can travel in many directions at the same time. However, Tesla was hardly recognized for his inventions and radical innovations. He was considered outcast from the science community and ultimately went into seclusion. It was not until decades after his death that people began to truly realize the genius that was Nikola Tesla.

Nikola Tesla

Tesla, none-the-less, was a visionary. A mind well beyond his time. He tried demonstrating his device (the Tesla Coil) for using Alternating Current at the World Fair in 1893 — World’s Columbian Exposition in Chicago.

Within the room was suspended two hard-rubber plates covered with tin foil. These were about fifteen feet apart, and served as terminals of the wires leading from the transformers. When the current was turned on, the lamps or tubes, which had no wires connected to them, but lay on a table between the suspended plates, or which might be held in the hand in almost any part of the room, were made luminous. These were the same experiments and the same apparatus shown by Tesla in London about two years previous, “where they produced so much wonder and astonishment”.

Barrett, John Patrick (1894). Electricity at the Columbian Exposition; Including an Account of the Exhibits in the Electricity Building, the Power Plant in Machinery Hall. pp. 268 – 269. Retrieved 29 November 2010.

Tesla's Machine

What a remarkable idea, right? Wireless electricity developed in the 19th century? We’ve only just began to experience wireless technology in mainstream society not more than at the turn of the 20th century. Yet, here is a man far removed from our times that already thought of this idea. In fact, Tesla built a tower, called the Tesla Tower (also referred to as Wardenclyffe Tower) in Shoreham, Long Island, New York for wireless telecommunications that operated between 1901-1917. Eventually, his investors, J.P. Morgan, cut off his funding because Tesla wanted to use this tower for allowing people to transmit telephony and broadcast wirelessly and for free. Of course his investors could not make a profit this way so they pulled out and the tower was never complete. Imagine, wireless, limitless, global communication, that was free! Does the Internet start to sound like less and less of a new revolutionary idea, now? Perhaps you might still not think so, but what will surprise you next is that this wasn’t even the first time someone has proposed, or even built such a technology!

 Tesla Tower

Back To Ancient Egypt

In order to understand even further, where we went wrong with today’s so-called “energy crisis” we must travel even farther back in time to the time of Ancient Egypt. The time of the Pharaohs. A time when civilization had clearly left its mark on the face of the world. Man-made structures. Tall, magnificent structures left behind by an ancient civilization that is no longer around today. Heritage, culture, language, artifacts, and even a tremendous wealth that were all left behind for us to discover. From these remnants what scientific evidence have we actually discovered about this civilization?

The Great Pyramid of Giza

You may have been led to believe that the Pyramids of Giza were used as tombs for Kings. If this is what you were told then you were lied to! Albeit, it’s quite possible that the people who lied to you were themselves lied to or just merely misled. It wasn’t an intentional sinister lie. It was one of misunderstanding and ignorance. Archaeologists have been hard pressed to explain the many mysterious of the Pyramids of Giza, because they were among the largest and most mysterious of all the Pyramids we have discovered today. Despite the mostly mythical notions about these Pyramids in Giza, Egypt being used for  the tombs of Kings, the truth is they were the power plants of the ancient world. Yes, Pyramids, were power plants of Ancient Egypt. How? Science tells us the story we were too stupid to understand when we first started exploring them.

Hieroglyphics in the temples of ancient Egypt explain the light-bulb

These are hieroglyphics from a temple in Egypt depicting that Pharaohs used light-bulbs long before we ever thought electricity had been discovered. Furthering the evidence for this claim is that if the ancients did not use electric light bulbs (depicted by the Pharaoh in this hieroglyph holding a bulb connected to a wire which is powering the luminous bulb from the Sun God Ra) they would have had to use flaming torches to see inside the corridors of the Pyramids. Torches would have left a residue of soot inside the chambers and corridors of the Pyramids. However, there is no evidence of any soot. The ancients did not see in the darkest bowels of these structures by way of fire as we once had believed.

It seems that the ancient civilization we deemed inferior to our own in technology and scientific advancements were so superior that ironically we failed to realize by just how much. Not only is there scientific evidence of technology apparent in the inscriptions left-behind from this civilization, but there is proof in every aspect of their work that we have only recently begun to unfold within the last few decades. For one thing, the mummies discovered in Egypt were all found in burial places such as the Valley of the Kings, which is a site far far removed from the Pyramids of Giza, or in other smaller pyramids and tombs that are not the great pyramids of Giza. There was not a single mummy found in these Pyramids. In fact, there isn’t even a single Hieroglyphic marking inside the Pyramids. Most tombs, temples, and burial places exhibited explicit inscriptions about their purposes; clearly marking that they were the resting places of Kings or Pharaohs. The Pyramids of Giza, however, did not. They remain a deep mystery – to this very day. Some of their secrets are yet to be discovered.

Pyramid Corridor

Think of it this way. If you were building a nuclear reactor, would you decorate it with art work and describe its uses and purposes openly? Surely, you would not. Today’s nuclear reactors and power plants are tightly secured structures; their secrets close-guarded by those only granted clearances into its deepest borders. Like-wise the Pyramids were only unraveled through close observation and careful study. Early Archaeologists only depicted these structures as the tombs of Kings because when they were questioned about their purposes and significance to the civilization they could come up with no other logical explanation. So they simply tried to deduce what might have happened to the mummies by hypothesizing that the sarcophagi and/or their mummies had been stolen by grave robbers along with any riches they may have found within. However, there is no evidence of there having been any riches in these structures. Would you store money in a power plant? There is no evidence of any sarcophagus lingering anywhere about in the corridors or chambers inside of the Pyramids. What we found instead in the Great Pyramid of Giza was what looked like it might have been a place for a sarcophagus, but turns out to have had a much different purpose.

Pyramid Schematic

Buried deep beneath the Great Pyramid of Giza sits a chamber with a single granite compartment showing clear evidence that it had been carved from a single slab of a special kind of granite. Granite is naturally radioactive. Certain types of granite have proven to have up to 10 PPM (parts per million) uranium. The zig-zag style corridors inside of the pyramids indicate passage way to aquifers leading from the Nile river beds to the underground chamber beneath the Pyramids vast structure. The water was used as a conductor in the production of electricity. Though the Pharaohs were not manufacturing electricity the way we are used to today. They were harnessing natural electricity. In Physics, we refer to this as subtle energy. It’s the use of implosion energy, not today’s more common explosion energy that set this civilization apart from ours by centuries and centuries of being in the dark ages. The Pyramids were coated with limestone from the outside. Limestone is a poor conductor of electricity. It was used as an insulator (in its pure calcium form). The granite, being a good conductor of electricity was used throughout. The top of the Pyramid was fitted with a huge block of gold as a cap. This is no longer present today, but at the time before it had been removed – or stolen – it was believed to have been used to conduct electromagnetic energy from the sun (the ionosphere). Gold is a perfect conductor of electricity and this would have been the equivalent of today’s solar-power cells used in so-called green-energy. The Pyramids, however, did not just produce or harness the suns energy or the planets natural energy – they had an even greater functional purpose. They were engineering feats of the ancients of our world to build infrastructure that would supply all of Egypt with wireless, safe, and limitless energy. They were crafted with the utmost precision.

Pyramid

Imagine, not only could you use these structures to power light bulbs and other tools, but you could power the people. The human body is the perfect conductor of electricity and can be used to safely pass electric energy current through the skin without harming the human being. Portable, efficient, safe, and best of all renewable energy! Is this not the mark of a genius civilization? A technologically advanced civilization? Yet, today we pride ourselves in having built microchips that produce immense heat, cost untold amounts of electricity – a result of harmful fossil fuels, and plead to be advanced.

The Pyramids are now theorized to be the greatest proof that ancient civilizations were indeed in position of advanced technology that even today we have not managed to acquire. In fact, with all of our technology today we still can not reproduce these magnificent structures that lay and remain in their place for more than 5,000 years!

The Great Pyramid of Giza is made up of more than 2.3 Million stones. Each stone weighs in at around 2 or 3 metric tons. That means this structure required people to cut, move, and assemble more than 6 or 7 Million tons of stone. By comparison, each of the World Trade Center Towers of New York City weighed around 500,000 tons. That’s an order of magnitude less than the Great Pyramid of Giza. Additionally, we know where the stone came from because of its mineral compositions having been tested. They were hauled from mountainous regions hundreds of kilometers to the south of Giza. Some Archaeologists might have you believe that these stones were moved using ropes, and piled on top of logs and raised with simple pulleys. Dragging two metric tons across the desert over a hundred miles? Sure, these men and woman all had Ph.Ds from fancy Universities! Lets give them credit for their imagination if nothing else, but in what science can you convince the world this explanation can be scientifically proven? Where did we find millions of logs of timber in the middle of the dessert? Further more, how many man hours do you calculate it would take hard laborers to move all these stones? It would have taken centuries at their populations. Beyond that there is evidence of pure craftsmanship everywhere in the Pyramids. The stones are cut to a fine edge with what could not have possibly been accomplished using mere stone and copper tools of simpletons. The stones are assembled with such precision that it defies all plausible rate of error, beyond that of which our modern-day engineers can even fathom. This is simply outstanding evidence that we haven’t even bothered to consider the possibility that perhaps it is us who are the inferior civilization. Perhaps we are only assuming the ancients were living in the dark ages, because their knowledge had been lost and it is our ancestors that were the ones thrown into the dark ages only of late. Now that we are merely just emerging from these dark ages it can not be so difficult to believe that previous ancient civilizations may themselves have once been at the height of technology and scientific advancement. Perhaps even so much so that they surpassed anything we have done to this very day by centuries.

You Are Not Dependent On Fossil Fuels

The lesson to learn from all of this is that fossil fuels are not the only source of suitable energy that can power our planet. Not only did scientists find proof of this technology among the Ancient Egyptians, but even the Mayans, the Chinese, and ruins discovered in European countries demonstrate the existence of Pyramid structures all around the world that may very well have been used for the same purposes. Tools that would compare to today’s only recently sought technological advancements like the quartz crystal, power tools that can cut through hardened materials like granite, and much much more.

Tools from the ancient civilization of Egypt

However, as long as there are greedy people in the world who would have an interest in controlling the worlds energy markets and controlling you to continue buying from them what seems like a product that can be depleted and run out – there will be such gimmicks to try and keep you in the dark about how much we can do without our horrible idea of energy today. The harm and the costs that it has burdened us with is beyond unacceptable.

It’s no new notion that we should turn to alternative, clean, renewable energy sources. We’ve been arguing and debating about this for decades, perhaps even centuries. Take a look at what the smart corporations are doing today about the energy problem. Google has invested a great deal of money in finding clean, renewable energy sources. They have even recently started a subsidiary – Google Energy – to fund this initiative and perhaps even pave their way into reducing the worlds energy costs through clean renewable energy. Google actually finds locations for its data centers in Asian countries were a steady flowing water supply, such as a river, or an ocean is nearby. It engineers and powers its resources based on ancient technology (building damns for power). Natural energy is all-around us. It flows freely throughout the earth in ways we are only beginning to discover. Tesla discovered this in the late 19th and early 20th century when he demonstrated how his device could power a light bulb without wires by allowing the alternating current of thousands of volts to flow through a human body and into the bulb, without harm to the person. Today, trying to touch a high-voltage wire of just a few thousand volts would surely kill you. Tesla’s Tower was powered by aquifers very similar to the ones the Ancient Egyptians used in their Pyramid. Today an unfortunate natural disaster in Japan nearly caused a nuclear melt-down and put millions of innocent people in harms way. There is no need to even mention the war, death, and destruction crude oil has caused us in the last few decades alone. Why are we bringing harm upon this world in order to help its people? If energy really is supposed to help us produce technology that helps and not harms the civilizations of this world then why doesn’t it?

I urge all of you to ask more questions and accept less things at face value. I encourage you to explore the true nature of science and technology as you are being taught in your schools, your homes, your places of business. Where does the world’s interest truly lie and who is trying to simply cover your eyes in order to fill their own pockets? If we were not really taught the truth in history class — how wrong could our science classes have been?

The Internet Blackout: SOPA

Today a large number of popular websites have participated in the Internet Blackout used as a protest against SOPA. It seems that while some websites have decided to block their service entirely from the public in order to raise awareness about the SOPA act and in an urgent call to get Americans to act, others have taken a more subtle approach.

For example, websites like reddit, mozilla, imgur, and wikipedia‘s English site have chosen to completely blackout from the public. While wikipedia is easier to get around than others sites like reddit, mozilla, and imgur are pretty much going to leave you empty handed for the day. Google simply blacked out their logo today and provide a direct link on their front page. If you’re visiting Google for the first time today you might have been redirected to the announcement page to contact your local senator. Beyond that they don’t seem to nag you like other sites are doing. Sites like WordPress, php.net, and Google took an elegant, but effective approach to the blackout. They demonstrated their anti-SOPA while still keeping their visitors happy. Sites like Bing and Yahoo, however, don’t seem to have participated in today’s blackout in any noticeable way.

Internet Blackout - SOPA

Internet Blackout - SOPA

Read more about the SOPA Strike here.

Why You Need a Database

There are a lot of developers that start off building their applications with the notion that a database is only necessary if they have a lot of data to work with or that the data they have will be easier to manage if they can avoid the complexities of building and maintaining a database or dealing with a DBMS (Database Management System). In the area of web-based development, this is rarely the case. The reason for this is that web-based applications tend to grow very rapidly. This is easy, because there are billions of people with access to the Internet and virtually anyone with access to the Internet usually gains such access from a web-enabled device. Having access to the Internet has become synonymous with having access to the world-wide web. Since the number of potential users is so huge the potential for data is equally huge. Not only that, but beyond the sheer amount of data that maybe collected from users of the application software and stored for use by the system there is the factor of maintainability. Databases make organizing and maintaining long-term data easier. This comes in several forms. Without a database solution you have to worry about concurrency issues for replication. You would also have to consider race conditions, access time, permissions, and scalability among others.

Databases Are Overkill

For those who start off building small web-based applications or even trying to put together a tiny CMS (Content Management Systems) they sometimes fall victim to the illusion that having a very small amount data would mean that building a database for this data would be overkill. This is simply not true anymore. Today databases are easier than ever to build, grow, and manage. With lite-weight solutions like SQLite you actually improve on performance with small amounts of data and make it easier to manage. SQLite is actually a small foot-print library written in C that implements an embedded DBMS. It’s only a few hundred KB in size and implements most of the SQL standard. You can use it to store databases in memory or on disk and still get the full benefits that relational databases offer with a minimalistic foot-print and without compromising on performance for small data sets. It’s adopted by PHP, Python, Perl, Ruby and even Javascript as well as many other languages. So there really is no excuse to avoid using a database when the solution is widely available in so many popular platforms and especially in web development.

Databases Are Slow

This could not be farther from the truth. A relational database can maintain indexing for records across different tables. This means rather than looking through the entirety of the data set and then trying to expose some underlying structure in order to find a particular set of data the relational database takes advantage of composing structures as you build your data sets. These structures make things like fetching a record with a primary key much much faster than you would get by using a flat-file solution.

Lets examine the alternatives. Even if you had a very small amount of data – say just a few hundred lines of text. Even if the data structure was overly simplistic – we’ll assume each line represents what would be a single row in a database table. Even if the data will only ever be maintained by a single developer – you. You are still overlooking so many problems that are not easily solved by using a flat-file to maintain this data. First lets consider the race-condition. You have a script that opens a specific file on the server and appends a new line each time a record is added. The script can also open the file for reading and retrieve the entire contents of the file into memory. The script can then do any necessary sorting and filtering to return the required data sets to the user. The most apparent problem with this approach is the race condition. It is entirely plausible that two requests could be made simultaneously to the same script – one to open the file for writing and append a record and one to open the file for reading and retrieve the data. If the data is stored into memory before the line is appended the result is stale and potentially corrupt. If the new data is appended before the read, no problem. However, what happens when you want to delete a record. Now the problem is three-fold. If three individual requests all come in at the same time – one to read, one to write, and one to delete a record – it is now likely the case that your entire data structure has been corrupted. Remember that HTTP is built on a request-response model and no two requests are treated as if they are tied to any previous requests. So there’s no central point of control over your script’s ability to manage which process can access the data and to what extent.

In a DBMS, on the other hand, the control is transferred away from the script and to the central management system of the database. The DBMS then gets to decide how requests will be served and the order of treating the data. This creates more dependable data that has a far lesser chance of corruptibility. Now, it’s entirely possible that you may not be concerned the integrity of your data for a small application, but then you might as well not waste your time building it.

I’ll Use A File Now And Learn To Use A Database Later

If you’ve said this phrase it’s already too late. It doesn’t take a lot of time to get started with a database in the first place. If you’re using languages like PHP, Python, Perl, or Ruby you probably already have the necessary libraries installed on your system to work with a database. These libraries and drives are usually packaged with these software stacks as standard. It’s actually uncommon to not have some DBMS solution already available in most of these environments. So why would go out of your way to reinvent the wheel when the solution is already at your fingertips? Not only that, but it takes very little time to set these DBMS solutions up and get them to run smoothly on virtually any platform. You will probably spend more time trying to write a script that stores, retrieves, sorts, filters, locks, and validates data using a flat file then you would installing the DBMS and getting a simple schema started.

If you’re using PHP interfacing with a database has become easier than ever. It only requires a couple of lines of code to open a database connection to virtually any database you have a PDO driver installed and loaded for in PHP. So whether you’re using SQLite, MySQL, PgSQL, etc… you shouldn’t need to spend a lot of time learning how to interface with each of these databases if you simply stick with the PDO extension. You use the same functions regardless of the database. This is opposed to having to learn the individual database-specific extensions in PHP to interface with each of those databases. Not to mention PDO supports many of the popular new database features such as prepared statements and is a lot easier to learn and use than extensions like MySQLi.

PHP and Databases

Being a PHP developer, I also take notice of many PHP developers that tend to have the misconception that when they start using a database (usually it’s the case that their first database is MySQL) they should start by learning the old mysql extension in PHP. This is simply not true. Some of the underlying reasons this is widespread, however, is mainly due to the fact that the old mysql extension has been around for quite a long time in PHP and it’s fairly common to see a lot of PHP code demonstrating the use of a database in PHP using this extension. It’s also become familiar to a lot of old PHP developers and is bound to be present in their older applications. However, the use of the old mysql extension is highly discouraged for new development. It’s an old extension that’s no longer well-maintained and has been planned for deprecation for years. There’s no guarantee that if a new bug creeps up that someone will go back and fix it. This leaves your application vulnerable and exposed. If the code base gets large enough this might leave developers scrambling for migration path. Additionally, the extension does not support prepared statements or parameterized queries. This makes things like making sure you properly escape user data to avoid SQL injection, prone to error. The extension lacks in many areas that are not conducive to future development. Learning the old mysql extension first before you learn the new improved mysql extension in PHP or before you learn PDO will gain you nothing. In fact, it will cause you to have to unlearn some of the very poor design of the old extension and its implementation details in order to become more accustomed to the newer extensions.

Some developers also complain that PDO seems too complicated or more difficult to use than the old mysql extension. This might come from the lack of understanding as to what PDO even is or how its used. Since PDO can only be used with the newer OOP features of PHP (you have to use objects and methods instead of procedural-style functions) it makes it seem unapproachable or even scary to developers who aren’t used to OOP in PHP. There is also the idea that PDO has a lot more features due to its vendor-agnosticism and the fact that requires further configurations such as installing and loading the individual drivers needed for interfacing with your specific database (where the drivers aren’t already packaged or loaded). I can understand the intimidation, but most of this has been alleviated with new versions of PHP coming pre-packaged and loaded with most of the popular drivers and the documentation offering up examples that are now easier to follow and get started with. Most of the intimidation is actually coming from having to unlearn old habits that older extensions like the old mysql extension once taught.

Once you get past the initial intimidation phase and actually get started with a PDO and with a database you’ll find that it doesn’t take nearly as much time as you’d think to get up and running. Most of the reservations people have are 90% of what’s holding them back. Not that the investment to get started is actually that significant. Beyond that you’ll find that learning to build on data normalization not only make development easier, but makes your users happier. When you can organize and maintain data that’s more clearly structured and accessible you can serve your users more effectively and efficiently. That will keep users coming back and eventually help you grow your application!

Load Balancing Software as a Service

I’m sure many of you have seen this statue before, perhaps not the very same one in the picture, but possibly similar statues around the world. This one is located in New York City.

Statue of Atlas in NYC

This particular statue is the Titan Atlas (a God from ancient Greek Mythology) who was supposedly burdened with carrying the weight of the world – or the weight of the heavens – on his shoulders as a punishment from Zeus. Whether it was the weight of the world or something else is unclear, but most people seem to follow this same observation. In general it’s nothing more than a myth, but the lesson history teaches us is that it constantly likes to repeat itself. Clearly, no one can bear the entire weight of the world on their shoulders just like no one computer can either. If you are running SaaS (or Software as a Service) you are online 24/7 and so is your service. The problem is there are over two-billion users online (or with Internet access) today. What happens when too many of those users all start using your service at once?


What Is Load Balancing


The idea behind load balancing is that a single machine can only handle so much work at one time and you can only go vertical for so high. Notice that even in large cities you can only build so high before you have to start building out. Since on the Internet virtually anyone can be using your server at any time you run the risk of overloading without warning. If too many users all send requests to your server too quickly, the server will reach a point where the load is higher than its capacity and eventually crash. This particular vulnerability of typical client-server relationships on a network is exploited by what is commonly referred to as a DDoS attack or a Distributed Denial of Service attack. Basically, a number of clients (sometimes a bot-net controlled by one or more users) will attempt to send a lot of requests to a server or number of servers very fast in order to overload the server and prevent its intended users from being able to access the service. Sometimes this is done just to destabilize the service running on the server or for other malicious intents. There are ways to mitigate DoS attacks with firewall software/hardware or through other means depending on the service, but not all DoS attacks are malicious or even intentional in nature. Google, for example, experienced what was at first glance considered a DoS attack on its search service during one afternoon on June 25th of 2009. This actually wasn’t a malicious user or users at all. It was the world receiving the tragic breaking news of the death of Michael Jackson. Literally, millions and millions of users from all around the world flooded Google Search all at once with the same search phrase “Michael Jackson”. Google had never seen such a tremendous amount of traffic coming in all-at-once on a single search query, before, so their first thought was “ohnoes, we’re getting DdoSed!

Scaling Out - SaaS

Scaling Out - SaaS


Why Do I Need It


The fact remains that any number of users can suddenly surge the number of requests coming in to your servers at any given time and whether that is malicious or not is unimportant. What is important is that you are better prepared to handle such situations so that your service will suffer as little downtime and degradation as possible. So load balancing allows you to distribute the load on a particular service or services over a larger array of resources. It’s basically making your service, as a whole, more tolerant of failure by being able to efficiently make use of all available resources.

If you are running any kind of high availability service over the Internet you need load balancing. Though, even small applications with just a few thousand users can benefit deeply from load balancing, as well. The only potential down-side is that you may need more than just one node to it. This isn’t always necessary as load-balancing can come in many shapes and sizes. For example, you might be doing load balancing on the same host node using multiple guest nodes on the same machine. All of the major services you probably use on a regular basis like your email, search engines, or popular social networking apps all make use of load balancing because it keeps things running a lot more smoothly as the number of users grow. If you’re not on-board with this yet – you probably should get on board quick.


How Do I Use It


There are few broad categories you can place load balancing techniques in. The easiest form of load balancing relies on existing system already built on top of how most systems function over the Internet (or large networks in general) and that’s DNS. DNS is a distributed system so it relies on multiple components in the network to do their job in order to make things more efficient. It reduces bottle-necks like those created by routing enormous amounts of packets across the planet in fractions of a second. Like most complex systems everything starts off small and simple and grows both horizontally and vertically, but at the core the protocols are fundamentally very simple.

DNS Load Balancing is simply relying on the DNS system to take care of the most basic problems for you. The way this works is you set the DNS record for a particular domain name to multiple IP addresses (usually one for each server) using low TTL (or Time to Live). Since DNS is cached at various levels this makes things like geographical loads efficient for services like name servers. A name server tells the DNS where to send the request for a particular domain name and can route packets to different locations depending on the geographical origin of the request thus alleviating network latency and allowing packets to travel shorter distances. Once the request comes in and is routed effectively the DNS is cached at multiple levels so that future requests are made to the same place. This can be cached at the local level, the ISP level and other levels in the parent zone. The name server then doesn’t become a bottle-neck since not every single request has to rely on that name server entirely. There is a TTL involved that will let the caching servers know when the cache has become stale and that it’s time to refresh. Also when requests to a particular server are no longer getting through the DNS server will know to try a different IP. So if you have different servers with different IPs in the DNS record that ultimately means if one server becomes unresponsive (potentially having gone down) the load is directed to a different server. The inherent problems with this approach are that it isn’t making very efficient use of all of your resources. It doesn’t take into account which servers are currently busy and if the DNS record has already been cached to a server that is now down you end up potentially being stuck with a poorly responsive server until the cache is refreshed. Additionally, you are exposing your infrastructure to the outside world by revealing the public IPs of your servers with no way to control the flow of traffic to an internal network. It’s very easy to have an unstable system this way. Most services that use this approach are usually just creating what is known as mirrors (servers that back each other up so that in case one goes down a backup can still be reached).

Software Load Balancing is another approach to solve some of the short-comings of the DNS offloading techniques described earlier. Software load balancers attempt to keep track of the available resources and when an incoming request is received it determines how to best allocate those resources in-order-to service that request. The benefits of this technique are that you don’t have to reveal your network setup to the outside world. Everything can be done on the internal networking configuration setup (whether that’s a local area network or otherwise), or in other words, you won’t expose your communication channels directly. Also, you have a tighter hand on security and distribution since you can more easily control the flow of traffic over the network. Some examples of common open-source load balancing software are Pound, Varnish, mod_proxy for Apache’s httpd, and Gearman. There are all sorts of nifty ways to balance the load across your network. You can have the load balancers poll the servers and check on resources like CPU usage, available memory, storage space, network traffic or open TCP connection, etc… The load balancer can then use this information to figure out how to best direct the incoming requests and serve up the responses as quickly and as efficiently as possible. There are still a few problems inherent to this technique depending on how you use it. If you’re only relying on a single machine you have a single point of failure. If the host node goes down the load balancer and all of your resources go with it. If you’ve only got one load balancer and multiple servers you still have a single point of failure. Additionally the load balancer itself can be DoSed given an attack of enough magnitude and proficiency. Not only that, but you have to worry about things like session storage consistency across multiple servers, file-system access, database synchronization between different database servers, and some network bottle-necks that might not always be easy to resolve with load balancing – to name a few.

Hardware Load Balancing there are some hardware load balancers as well. You can actually buy very expensive firewall/routers that take care of many of these things for you. Most people usually just setup a dedicated node or two with software load balancers that pretty much do the same thing. These hardware load balancers might do a better job of handling security and high bandwidth loads like Cisco’s ASA, but they do come with a heavy price tag.


Some Load Balancing Tips


There are some pretty common approaches to some of the problem inherent to distributing a service over multiple servers. For example, take your session storage as the most obvious problem. If you’re using PHP you are probably using the built in session handler, which makes use of file-based sessions. If you have users being directed to different servers by the load balancer you end up with the user having multiple sessions across those servers (that might be a little problematic for your application and annoying to the user). Some people will try to avoid this by creating what’s called a sticky session. Once the session is generated for that user they’re sent a cookie that lets the load balancer know upon subsequent requests to direct the user to this particular server. There are a few minor problems with that, but nothing you couldn’t work out through a well-planned architectural approach. Another way to approach this is by creating a centralized session storage server where all the requests will look for the session. Depending on your infrastructure this may or may not be a good idea and keep in mind it also creates a single point of failure. For example, if your servers are built on stacks (you have several software-based servers running on the same node like a webserver, database server, application server, etc…) it takes some tinkering to configure each stack to work from a centralized session storage. You can use something like Redis where you can have master/slave replication across all stacks. This takes a little less configuration and puts the dynamic into the software stack layer – thereby removing it from the load-balancing layer.

The other obvious problem is file system storage. If you allow your users to upload files to your server, or you store large amounts of files that your application relies on heavily, there needs to be some system whereby your application layer can access those files considering the load balancing may send requests to different servers. Again there is a centralized approach like with session storage, but even with a replication approach – to avoid the single-point of failure down side – you might create the problem of over redundancy. If your servers are set up in stacks having four or five copies of each file (or more depending on how many servers you have) on each server stack is a bit of a waste, especially if you’re already using RAID arrays for redundancy. Even if you have a centralized set of servers for storage you still face the problem of network overload. For example, consider that if your backbone bandwidth capacity is at 100Mbps but your central network bandwidth capcity is at 10x100Mbps you eventually create a bottleneck with increased usage as your backbone can only serve up to 100 megabits per second of traffic at any given time.

Using a CDN (or Content Delivery Network) is one solution often used when large amounts of files need be shared across a network, but this can also be a bit costly depending on your needs. In its simplest form a CDN is really just a group of servers that store files or data objects for you and replicate them across multiple nodes allowing many other servers on the network to access that data with improvements in caching and high bandwidth to reduce latency. The servers in the CDN clusters are usually strategically located on the edges of the core network to minimize the bottlenecks involved in the centralized network loop. So you are redirecting the traffic to access file storage away from the central network and off to the edge servers expanding on bandwidth and minimizing on bottle neck traffic. This solves both the single-point of failure problem as well as taking the complexity mechanism away from the server stack which can ultimately help reduce loads and create more efficient load balancing. Most services that utilize CDNs are usually ones that need to offer high-bandwidth access to a large user base with consistency. For example, a service that offer Hi-Definition video streaming, large photo sharing web sites, or other media services with high availability needs. You don’t always have to build this infrastructure yourself. You can rely on services like amazon Cloud Front which is a pay-as-you-go CDN service offered by amazon. There are many other competitors, of course, that can offer cheap CDN solutions. Depending on the sensitivity of your data this may or may not be an option for your particular SaaS needs. Still something to consider.

Besides just file storage you probably have a lot of database concerns in a system that scales horizontally, as well. If you’re just using a single LAMP stack with little more than PHP, MySQL and Apache running your back-end it might seem easy to scale wide at first. The problem you’re likely to run into head-on is the data-replication across your MySQL servers. The database is almost always the biggest bottleneck in SaaS. It usually contains tons of data that virtually every one of your users will access with each hit. There’s only so much traffic a single database server can handle, but setting up two or more database servers can show some significant improvement. Your load balancer can also play a role in this. There can be data object caching mechanisms in place to ease off some of the load for the most frequented queries. There can also be network latency issues to deal with once you have several database servers all replicating (especially if these servers are geographically spaced out across different data centers, cities, countries or even on different continents). Chunking is definitely not something I’d advice. It throws way too many variables into the equation and presents more problems than solutions – for the most applications.