Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
Found the internet!
Posts
Communities

Posts about Python

Subreddit Icon
r/Python
1.0m members
News about the programming language Python. If you have something to teach others post here. If you have questions or are a newbie use r/learnpython
Visit
Subreddit Icon
r/learnpython
645k members
Subreddit for posting questions and asking for general advice about your python code.
Visit
Subreddit Icon
r/pythontips
84.4k members
A place to get a quick fix of python tips and tricks to make you a better Pythonista.
Visit
r/learnprogramming
3.4m members
A subreddit for all questions related to programming in any language.
Visit
Subreddit Icon
r/madeinpython
15.3k members
A subreddit for showcasing the things you made with the Python language! Use us instead of flooding r/Python :) Hey check out r/madeinjs for JavaScript and Typescript!
Visit
r/PythonProjects2
23.8k members
A place for people who are learning the programming language 'Python' to come and apply their new skills on actual projects, and get feedback.
Visit
Subreddit Icon
r/PythonJobs
11.7k members
Python jobs are posted here
Visit
r/coolgithubprojects
45.5k members
Sharing Github projects just got easier!
Visit
Subreddit Icon
r/AskProgramming
86.4k members
A subreddit for all your programming questions.
Visit
Subreddit Icon
r/MachineLearning
2.5m members
Welcome to r/MachineLearning
Visit
Subreddit Icon
r/todayilearned
29.0m members
You learn something new every day; what did you learn today? Submit interesting and specific facts about something that you just found out here.
Visit
r/coding
398k members
Welcome to r/coding
Visit
Subreddit Icon
r/forhire
286k members
Some redditors are skilled professionals, some redditors need skilled professionals. Scroll down for general information and our rules. Please read through these carefully, as breaking them can be a bannable offense.
Visit
Subreddit Icon
r/Sneks
296k members
Where sneks come to hissss
Visit
Subreddit Icon
r/ProgrammerHumor
2.4m members
Dedicated to humor and jokes relating to programmers and programming.
Visit
Subreddit Icon
r/ballpython
78.5k members
Python Regius. Royal Python. Ball Python. We love them by any name!
Visit
r/pythoncoding
23.9k members
**/r/Pythoncoding is a subreddit for advanced Python content.** Developers can share articles and news about the Python ecosystem, deep dives into Python intricacies, or showcase advanced projects they are working on.
Visit
Subreddit Icon
r/datascience
811k members
A place for data science practitioners and professionals to discuss and debate data science career questions.
Visit
Subreddit Icon
r/ProgrammingBuddies
39.6k members
A place for people to group up to learn and teach programming to each other.
Visit
Subreddit Icon
r/programming
4.7m members
Computer Programming
Visit
Subreddit Icon
r/algotrading
1.6m members
A place for redditors to discuss quantitative trading, statistical methods, econometrics, programming, implementation, automated strategies, and bounce ideas off each other for constructive criticism. Feel free to submit papers/links of things you find interesting.
Visit
Subreddit Icon
r/raspberry_pi
3.1m members
A subreddit for discussing the Raspberry Pi ARM computer and all things related to it.
Visit
Subreddit Icon
r/django
105k members
News and discussion about the Django web framework.
Visit
Subreddit Icon
r/snakes
178k members
A place for snake owners and lovers to share snake related stories, pictures, advice, and ask questions.
Visit
Subreddit Icon
r/EliteDangerous
325k members
The official unofficial subreddit for Elite Dangerous, we even have devs lurking the sub! Elite Dangerous is a space simulator game by Frontier Developments based in the year 3308. Your CMDR flies spaceships and participates in exploring a 1:1 scale Milky Way, trade between star systems, bounty-hunting wanted ships, discover alien lifeforms, and even pirate other ships for their cargo.
Visit
r/reptiles
128k members
A cozy place for anyone who loves cold-blooded creatures of the world.
Visit
r/learnmachinelearning
274k members
A subreddit dedicated to learning machine learning
Visit
Subreddit Icon
r/videos
26.6m members
Reddit's main subreddit for videos. Please read the sidebar below for our rules.
Visit
Subreddit Icon
r/gis
81.5k members
A community dedicated to everything GIS (Geographic Information Systems).
Visit
Subreddit Icon
r/funny
43.5m members
Welcome to r/Funny, Reddit's largest humour depository.
Visit
8.4k
Subreddit Icon
Posted by10 days ago
OC
Post image
8.4k
356 comments
3.9k
Posted by2 days ago
View Comments
Play
0:00
0:00
Settings
Fullscreen
3.9k
143 comments
2.8k
Subreddit Icon
Posted by9 days ago
Post image
2.8k
236 comments
2.1k
Subreddit Icon
Crossposted by11 days ago
2.1k
244 comments
1.4k
Subreddit Icon
Posted by8 days ago

I am a one-man show building a web-based software product. Some quick facts about my app:

  • Written in Python Flask

  • 150k visitors per month

  • 15k registered users

  • 3k US$ revenue per month

  • 70 requests per second at peak-time

This is a technical post looking at the infrastructure that runs my app with a focus on how I deploy it.

Summary
  • I use 2 VPS (virtual private servers) running on DigitalOcean

  • The database is Postgres and is fully managed by DigitalOcean

  • I use a blue-green deployment

  • Deployment is done via git and ssh.

  • No CI/CD

  • No containers

  • Absolutely no Kubernetes

I am a strong advocate of using "boring technology". I am also the only developer of the app, which makes many things simpler.

The application infrastructure

The app is a CRUD monolith that is deployed as one artefact. I use nginx and gunicorn to serve the app.

The app runs on 2 virtual private servers, one of which is the production server, the other of which is the staging server. During deployment, they switch roles. This is a so-called blue-green deployment, more on that later.

I'm using a DigitalOcean droplet with 8 shared CPUs, 16GB of memory and 80 GB of storage for each server. They both run Ubuntu which I have to administrate.

There is a single Postgres database, which is always in production. It is fully managed by DigitalOcean, which means I have to do no house-keeping. Currently, it has 4 shared CPUs, 8 GB of memory and 115 GB of storage.

Overall, the setup is absolutely rock solid. Also, all my technology is older than 10 years (OK, not 100% sure about this, but probably true).

Why I chose blue-green deployment

Before I switched, my deployments worked as follows:

  • There was one app server running on DigitalOcean, plus the hosted Postgres database.

  • To deploy, I used a script that SSHed into that server and did a git pull

This was fine to begin with, however there were several issues:

  1. My setup compiles and minifies CSS and Javascript on the server. This resulted in up to 10 seconds for the server to respond after a deployment. Some users ran into Bad Gateway errors 💥.

  2. A bug in production could be fixed by checking out the previous commit. However, this invariably took too long and always involved frenzied googling of the correct git commands.

  3. There was no way of testing the production setup, other than in production.


https://i.redd.it/vtnhdavf36q91.jpg
What is blue-green deployment?

Here's how I would explain blue-green deployment:

  1. There are two identical and independent servers hosting the application. One is called "green", the other "blue".

  2. There is a shared production database that both servers can access.

  3. There is a quick and painless way of routing traffic to the green or the blue server.

One of the 2 servers is serving production traffic (the live server), the other is idle. When a new release is ready, it gets deployed to the idle server. Here it can be tested and issues fixed. Remember, the idle server is still accessing the production database, so the application can be tested with real data.

Once you're satisfied that you're ready, you switch traffic from the live server to the idle server. If any problems occur, you can simply switch back within seconds, effectively doing a roll-back.

Simple, no?

How I do blue-green deployment

I've already mentioned my 2 application servers. But the magic thing that makes it all possible is a floating IP address from DigitalOcean.

This is a publicly-accessible static IP addresses that you can assign to a server and instantly remap between other servers in the same datacenter. My app domain (keepthescore.co) resolves to this static IP address. Internally, however, the IP is pointing to either the green or the blue server.

Both of my servers expose their hostname via a publicly accessible route: https://keepthescore.co/hostname/. Give it a try by clicking on the link!

So now it's possible for a human or a machine (using curl) to discover which the current live server is (blue or green).

The deployment script can use this information to always automatically deploy to the idle server. Here's my (simplified) BASH deployment script:

# Get the current production server and 
# set TARGET to the other server 
CURRENT=$(curl -s https://keepthescore.co/hostname)
if [ "$CURRENT" = "blue-production" ]; then
  TARGET="green.keepthescore.co"
else 
  TARGET="blue.keepthescore.co"

echo "Current deployment is " $CURRENT
echo "Deploying to " $TARGET

# Do deployment
ssh -q root@$TARGET "git pull"
echo "Deploy to " $TARGET " complete"

After I've run the script I can test the deployment on my laptop by simply pointing my browser to blue.keepthescore.co or green.keepthescore.co. Once I'm sure that everything's working I route traffic to the newly deployed idle server using DigitalOceans's web interface. (I could do this via script too, but haven't got round to it yet).

Result: My users get routed to the newly deployed software without noticing (hopefully).

Voilá! ✨

What about continuous integration / continuous deployment?

I have no CI/CD pipeline. I do have a bunch of integration tests, but I run them manually. I will eventually get round to setting up some kind of automated testing, but so far there's been no need.

Just to be clear: when I run my integration tests, they happen on my laptop and use a test instance of the database. It's only when I do manual high-level testing on the idle staging server that the production database is used.

What about the database?

There is only one database instance, so you might think this could be a problem. Martin Fowler, who wrote a great article about blue-green deployments says the following:

Databases can often be a challenge with this technique, particularly when you need to change the schema to support a new version of the software. The trick is to separate the deployment of schema changes from application upgrades. So first apply a database refactoring to change the schema to support both the new and old version of the application, deploy that, check everything is working fine so you have a rollback point, then deploy the new version of the application. (And when the upgrade has bedded down remove the database support for the old version.)"

I've been using this method so far. In fact, I have never done an automated schema migration of my database. It's worked great so far, so why do it differently?

That's all

Thanks for reading my article! You can follow my journey as a bootstrapped one-man startup on Twitter. See you in the next post!

One more thing: if you want to share this post, please consider using this link (which points to my blog)

1.4k
162 comments
579
1.0k
Posted by2 days ago

UPDATE: The sign ups have run out. You can still find the first 15 videos of the 50 video course on YouTube for free. Also, check out my new book with programming exercises for beginners for free or as a 99 cent ebook.

If you want to learn to code, I've released 2,000 free sign ups for my course following my Automate the Boring Stuff with Python book (each has 1,000 sign ups, use the other one if one is sold out):

https:// udemy. com/course/automate/?couponCode=OCT2022FREE

https:// udemy. com/course/automate/?couponCode=OCT2022FREE2

Udemy has changed their promo code and severely limited the number of sign ups I can provide each month, so only sign up if you are reasonably certain you can eventually finish the course. The first 15 of the course's 50 videos are free on YouTube if you want to preview them.

Instead of having unlimited free sign ups for 6 days per month, Udemy only lets me make 2,000 free sign ups per month. >:(

NOTE: Be sure to BUY the course for $0, and not sign up for Udemy's subscription plan. The subscription plan is free for the first seven days and then they charge you. It's selected by default. If you are on a laptop and can't click the BUY checkbox, try shrinking the browser window. Some have reported it works in mobile view.

Sometimes it takes an hour or so for the code to become active just after I create it, so if it doesn't work, go ahead and try again a while later.

Some people in India and South Africa get a "The coupon has exceeded it's maximum possible redemptions" error message. Udemy advises that you contact their support if you have difficulty applying coupon codes, so click here to go to the contact form.

I'm also working on another Udemy course that follows my recent book "Beyond the Basic Stuff with Python". So far I have the first 15 of the planned 56 videos done. You can watch them for free on YouTube.

Side note: My latest book, The Big Book of Small Python Projects, is out. It's a collection of short but complete games, animations, simulations, and other programming projects. They're more than code snippets, but also simple enough for beginners/intermediates to read the source code of to figure out how they work. The book is released under a Creative Commons license, so it's free to read online. (I'll be uploading it this week when I get the time.) The projects come from this git repo.

Frequently Asked Questions: (read this before posting questions)

  • This course is for beginners and assumes no previous programming experience, but the second half is useful for experienced programmers who want to learn about various third-party Python modules.

  • If you don't have time to take the course now, that's fine. Signing up gives you lifetime access so you can work on it at your own pace.

  • This Udemy course covers roughly the same content as the 1st edition book (the book has a little bit more, but all the basics are covered in the online course), which you can read for free online at https://inventwithpython.com

  • The 2nd edition of Automate the Boring Stuff with Python is free online: https://automatetheboringstuff.com/2e/

  • I do plan on updating the Udemy course for the second edition, but it'll take a while because I have other book projects I'm working on. If you sign up for this Udemy course, you'll get the updated content automatically once I finish it. It won't be a separate course.

  • It's totally fine to start on the first edition and then read the second edition later. I'll be writing a blog post to guide first edition readers to the parts of the second edition they should read.

  • I wrote a blog post to cover what's new in the second edition

  • You're not too old to learn to code. You don't need to be "good at math" to be good at coding.

  • Signing up is the first step. Actually finishing the course is the next. :) There are several ways to get/stay motivated. I suggest getting a "gym buddy" to learn with. Check out r/ProgrammingBuddies

1.0k
72 comments