Category Archives: Google AppEngine (GAE)

Using Google Cloud SQL from Go with GORM in Google Container Engine and Google Compute Engine

One of the things I find a bit difficult with CloudSQL is surprisingly the first thing you need to do – connect.

Being able to connect securely to your CloudSQL instance is sometimes a bit challenging not just in Go, but in Python as well.

In Go, I’ve found out conflicting suggestions and examples and after much trial and error I found a reasonable solution that works well.

After much searching I found CloudSQL Proxy which takes all of the IP white listing and SSL mess away by using direct OAuth APIs to obtain access to the instance.

While my example works specifically with GORM, which requires a nice database connection string, there are examples of using plain database/sql syntax with CloudSQL Proxy.

I know it looks simple enough, but without importing cloudsql-proxy it wouldn’t have been possible to use the “user@cloudsql(project-id:zone:instance-name)/db” syntax style that is scattered around the net.

3 Ways to Avoid Google AppEngine Lock-In

appenginetoserver

Google AppEngine is a Platform-as-a-Service (PaaS) offering that’s been around since April 2008.

It’s very easy to build a web app on it or use it as a backend for a mobile native app helping you focus on the code itself instead of the infrastructure to run it.

AppEngine’s (almost) infinite scalability is gained among other things by using AppEngine in combination with other services such as the DataStore – a schemaless NoSQL docuemnt database built for high performance.

All of these makes AppEngine very compelling and easy to use. However, it comes with a price – vendor lock-in. If you are locked into the various AppEngine platform code and services its going to be very hard to leave.

There are some options such as AppScale – which is an open source implementation of the AppEngine stack but its still limited to running your apps in a certain way – the AppEngine way.

If you are stating a new app or service and are considering AppEngine there are a few tips that can help you migrate off of AppEngine, if you chose to, with relative ease.

1. Choose a Web Platform That Can Run Outside AppEngine Easily

Regardless what language you choose to develop it, AppEngine encourages you to use their Web platform. While in most newer language that HTTP platform is very app agnostic, in some – like Python – its better to use something more robust.

Instead of using WebApp2 you can use Flask to develop on AppEngine. Flask is a very active Web application frameworks with lots of modules and add-ons that do anything from database admin scaffolding to authentication.

If you web platform is platform agnostic you can always run your app outside AppEngine on your own servers (like Google Compute Engine – GCP or Amazon’s Elastic Compute Cloud – EC2)

2. Encapsulate AppEngine or Google only APIs

Try to avoid using AppEngine or Google only APIs. It will be hard to replicate it exactly.

If you have to, make sure to encapsulate the Google API code with your own code so you will only have to update code in very specific places. For example, encapsulate the use of Memcache in AppEngine so you could easily move to your own memcached servers if needed.

3. Avoid Using Google Cloud DataStore

While Google DataStore is a very stable and useful NoSQL schema-less database it’s also AppEngine’s biggest vendor lock in since there is no exact replacement for its API that can be used to replace it.

Instead of using DataStore consider using Google Cloud SQL – Google’s MySQL hosted database. If you like the way data is mapped to objects in Google’s Cloud DataStore you can use various ORM solutions in multiple languages such as SQLAlchemny in Python, Gorm in Go,

Another option would be to host your own database on Google Compute Engine (GCE) like Postgres or MongoDB. You can use the Google Cloud Launcher to have a one click installation of Postgres , MongoDB, Cassandra, etc.

Using a 3rd party common database will allow you to easily migrate off of AppEngine if needed.