How To Create A Web Server In Python Using Flask

mainLet’s say you’ve built an interesting Python application that runs locally on your machine. Great! Now how can you make that application usable as a service or an API? A lot of times, people build many services that need to play well together to build a final application. An obvious solution to this is to build a web server like Django that can host your application and handle all the incoming requests. But building a full fledged web server seems like an overkill, especially when you are dealing with lightweight services that only need a couple of functionalities. This is where Flask comes into picture! Flask is a Python microframework that can be used to build web servers and create web applications. How do we do that? How do we build a server that can handle different types of requests?   Continue reading

Launching A Spark Standalone Cluster

1 mainIn the previous blog post, we saw how to start a Spark cluster on EC2 using the inbuilt launch scripts. This is good if you want get something up and running quickly, but it won’t allow fine-grained control over our cluster. A lot of times, we would want to customize the machines that we spin up. Let’s say that you want to use different types of machines to handle production level traffic in different regions. May be you are not on EC2 and you want to launch some machines in your cluster. How would you do it? This is the reason we have Spark Standalone mode. Using this method, we can manually launch any number of machines independently in our private cluster and make them listen to our master machine. It gives us a lot of flexibility! Let’s go ahead and see how to do it, shall we?   Continue reading

How To Launch A Spark Cluster On Amazon EC2

1 mainApache Spark is marketed as “lightning fast cluster computing” and it stands true to its word! It can do amazing things really quickly using a cluster of machines. So how do we assemble that cluster? Let’s say you are using a cloud service provider like Amazon Web Services. Do we need to spin up a bunch of instances ourselves to form a “cluster”? Well, not really! Spark can launch a cluster by itself and you can control everything from one machine. You just need to log into your main instance and Spark will automatically launch all the instances in the cluster for you. It’s beautiful! Let’s go ahead and see how to launch a cluster, shall we?   Continue reading

How To Add Swap Space On Ubuntu

1 mainWhenever you are building an application that’s memory intensive, you are bound to run into memory issues. Those out of memory errors are painful to deal with, especially when they happen during production. Before putting your code on your server, you need to make sure that it can handle the application’s memory requirements. But even if you are careful, something might still go wrong and you might end up running into memory issues. One of the easiest ways to deal with this is by adding some swap space. Now how will it help our case? How can we use it on Ubuntu?   Continue reading

How To Setup Nginx For Load Balancing?

1 mainLet’s say that you have a nice idea for a website and you want to host it somewhere to make it available to the users. To do this, you put your website on a server somewhere on the cloud. Then, you purchase a domain name and you redirect all the requests to this server. But you soon realize that you are getting too much traffic, and that your server won’t be able to handle all of it by itself. So you go ahead and get three more servers. Now you want make sure all your servers share the load in a nice way. How will you do that? We would like to avoid the situation where one of the servers is getting all the traffic, and the remaining servers are getting a small amount. That wouldn’t serve our purpose here! So how we do we handle this?   Continue reading

HTTP vs HTTPS: Latency Comparison

1 mainI recently came across the issue of latency differences between HTTP and HTTPS. It got me curious and I started looking into it. To give a quick introduction to those who are new to this, HTTP stands for Hypertext Transfer Protocol and it’s a protocol for communication over the internet. Whenever somebody types something into the address bar on their browser, the browser understands the address and displays the appropriate thing. When you look at the address bar, you usually won’t see the address beginning with “http” because modern web browsers hide it. If you copy that address and paste it into a text file, you will see the full address starting with “http”. The problem with HTTP is that it is susceptible to wiretapping and other kinds of attacks. So people came with a solution and introduced HTTPS. HTTPS stands for Hypertext Transfer Protocol Secure. As the name suggests, it is secure! It’s the same HTTP protocol layered with a security protocol. Now that brings us to the main question. Will this affect the internet speed in any way? Will this be an issue when we are dealing with large amounts of traffic on the internet?   Continue reading

Why Do We Need Two-Factor Authentication?

1 mainIn the last couple of years, we have encountered quite a few security breaches. A lot of internet companies are being targeted with these kinds of attacks. One of the most common forms of online transactions is that you have an account that’s protected with a password. So whenever you want to access your account, you just enter your username along with the password. But the problem is that this is breakable! As in, people can technically break into these accounts. So people started thinking about different ways in which this could be prevented. Of course, choosing better passwords would help, but we need to way to fundamentally improve the security. How exactly do we do it? Do we just choose bigger and better passwords or is there something new we can do?   Continue reading