How develop and deploy an application in the cloud. A referencial architecture (Part 1).

Rodrigo Ancavil del Pino edited this page Mar 27, 2014 · 4 revisions

I want to share my experience developing an application in the cloud. Today the cloud is an atractive option for developers, we don't need worry for low level details of the infraestructure.

This architecture shown us how develop our applications using services available in Internet.

I use Openshift to deploy a Django application and Redis in the Cloud for caching the site.

See the follow diagram.

Cloud-Diagram-Architecture-1

We deploy a site on Openshift using Django 1.6 Framework with the Python 2.7 runtime. To assure the performance of our site we going to use Redis.IO to cache the site.

Openshift (https://www.openshift.com) is our PaaS (Platform as a Service) with the runtime Python, Django and packages to connect Django with Redis (django-redis-cache and hiredis).

In Django's settings.py file, we set the values to connect Django with Redis.

  # If you want configure the REDISCLOUD
  if 'REDISCLOUD_URL' in os.environ and 'REDISCLOUD_PORT' in os.environ and 
     'REDISCLOUD_PASSWORD' in os.environ:
       redis_server = os.environ['REDISCLOUD_URL']
       redis_port = os.environ['REDISCLOUD_PORT']
       redis_password = os.environ['REDISCLOUD_PASSWORD']
       CACHES = {
            'default' : {
                 'BACKEND' : 'redis_cache.RedisCache',
                 'LOCATION' : '%s:%d'%(redis_server,int(redis_port)),
                 'OPTIONS' : {
                    'DB':0,
                    'PARSER_CLASS' : 'redis.connection.HiredisParser',
                    'PASSWORD' : redis_password,
                  }
             }
       }
  MIDDLEWARE_CLASSES = ('django.middleware.cache.UpdateCacheMiddleware',) +
                       MIDDLEWARE_CLASSES +
                       ('django.middleware.cache.FetchFromCacheMiddleware',)

For our example, we need to set the environment variables REDISCLOUD_URL, REDISCLOUD_PORT and REDISCLOUD_PASSWORD for our application deployed in Openshift. See for details in this link: https://github.com/rancavil/django-py3-openshift-quickstart/wiki/Django-1.6-with-Redis-Cloud.

Redis – Cloud is Redis.IO in the cloud (http://redislabs.com/), we need create us an account and create a database to get the endpoint information for the REDSCLOUD_URL and REDISCLOUD_PORT environment variables. When you create the database in RedisLabs, you put the password, you must remember, or see later in the admin web console, to config REDISCLOUD_PASSWORD.

You can see the endpoint information in the Manage Resources in the admin web console of Redislabs.

Manage-Resources-Redis-Cloud

Again, REDISCLOUD_URL and REDISCLOUD_PORT represents the address and port where Django locates Redis, RedisLabs in this case. When we created the resource (Redis DB) in RedisLabs (formely redis – cloud) we put a password, this is REDISCLOUD_PASSWORD.

If you want to see more details how create and deploy Django with Redis – Cloud on Openshift, check https://github.com/rancavil/django-py3-openshift-quickstart/wiki/Django-1.6-with-Redis-Cloud.

Well, now I want to share some aspect I consider important to keep in mind when we use the cloud to deploy our applications.

Advantages:

When we use an PaaS and his services in the cloud, there are a lot of advantages to consider.

  1. We don't need worry for the low level details of the infraestructura.
  2. We can focus in our application and his functionality.
  3. We have flexibility in the use of the resources.
  4. We pay only for what we use.

On other hand, we need to consider some issues when we use of services in the cloud. Remember, we are distributing our functionalities in the web.

  1. We must trust in the Service Level Agreements (SLA).
  2. We must trust in our providers.
  3. We need take all technical cautions to assure the application uptime.
  4. Consider the performance needs.

Finally, today we can trust in the cloud and develop good applications.