It is no secret that am a big fan of API centric app design. Its also no secret that I want you to follow this footsteps as well. Why? Because there is just so much love to go around. So below I have listed two of the top reasons this kind of design will benefit everyone in your development cycle
What is API centric design
First we begin by talking about an API. An application programming interface (API) is a source code based specification intended to be used as an interface by software components to communicate with each other. An API may include specifications for routines, data structures, object classes, and variables. This is the definition according to wikipedia. http://en.wikipedia.org/wiki/Application_programming_interface
API centric design is the craft of designing your entire application around APIs and API based concepts and best practices.
Why your users will love you
I am a firm believer in the maxim “Love your user” This is what we stand for and as an API Engineer here are some of the reasons I believe your users will love you.
- Well defined functionality: Thinking in terms of API inherently forces you to define concerns early on.
- Mashups: Its all about bringing value to the users. While your propriety software may have a lot of value to your current user base, there maybe an entire user base out there that could very easily benefit by being able to extend your user functionality
Why your clients will love you
- Faster turnaround: API centric apps tend to have a lot of reusable components. This ensures that you can quickly deliver your app to clients
- Better rates: With less code to write, you can, if you so wish, choose to pass on some of the cost benefits back to your clients.
- Future ready: New devices come up everyday, for example the mobile revolution is currently peaking and more users than ever are accessing the Internet via their mobile devices. With an API centric design your app is ready for mobile and whatever may hit next http://thenextweb.com/insider/2013/03/18/npd-us-homes-now-hold-over-500m-internet-connected-devices-with-apps-at-an-average-of-5-7-per-household/
Why your colleagues will love you
- Maintenance heaven: Due to the strict adherence to the single responsibility principle http://en.wikipedia.org/wiki/Single_responsibility_principle that this kind of design begs, your code will be far much more easier to understand and debug for your fellow devs.
- Collaboration: since responsibilities are handled entirely per API, this means that its far easier to have multiple developers working on the same project smoothly.
Why you will love you
- Money money money: With more and more resusable code, you spent less time developing new applications thereby saving you time and effectively increasing your income on fixed projects.
- Visibility: An easy to integrate with system is a developers dream, by making this dream come true your app can gain mass adoption within the developer community earning not only the developers as new users but also their users.
Well we are finally here, end of this 5 part session.
By now you should have learnt principles that you will need in building your next project with long running task.
However if you are running enterprise application or otherwise an application that may need high volume you may need to consider a more formal method of serving your users.
Below you will find some of my recommended sites.
Please note I do not get paid anything when you follow this recommendations, I only have them here because I think they will be useful to you.
Open source queuing libraries
- PHP-Resque: Built by the guys who built github, this is one of the most powerful yet easiest to implement queuing system out there. Its biggest weakness is that it borrows a lot from Ruby and may not be intuitive to use for hard core PHP devs. See more here https://github.com/chrisboulton/php-resque
- Mongo Queue: Schemaless databases are gaining a lot of ground in the dev community due to their relatively faster response times. If you are part of this wave, you may want to consider Mongo Queue for your job. It runs on Mongo db. See more here https://github.com/lunaru/MongoQueue
- Laravel Queue: Being a sucker for Laravel you all knew it had to make an appearance right 🙂 Seriously the Queue module for laravel is one of the easiest to configure and use. Plus it provides integration with third party commercial queue services if you need it. If there was no other reason to switch to Laravel this is it! See more http://laravel.com/docs/queues
Commercial queuing services
- Iron.io: At 10 million free API calls per month, this is the definitely the service you want. Not to mention integration is easy and is supported by numerous libraries. As a matter of fact Laravel supports this out of the box!! See more http://www.iron.io/
- Amazon SQS: Amazon is known for reliability and scalability. This is for you if you have some money to spend and reliability and scalability are an issue. With Amazon you get 1 million calls free http://aws.amazon.com/sqs/.
- Google Queue: This is last on the list because its only relevant to Google App engine users. This is not yet supported in PHP as of today (July 2013) but beta tests are in way to support php. In the meantime it doesn’t hurt to check out the docs for python https://developers.google.com/appengine/docs/python/taskqueue/queues.
I believe you now have the knowledge to build that next resource hungry task. Devs, go forth and build the world!!
by Jacob Chencha
Since telling is nothing without the showing. We have a very simple implementation of the above work.
The resource being created is a text document with time set every ten second apart for an iteration of ten.
Now this is a trivial application but should be able to show what we need. You can get a copy of the source files from github https://github.com/prodeveloper/long_running_script
Without further a do here are the files.
For this particular implementation I have chosen to choose one file for progress and one for storage, they are imaginatively named store.txt and progress.txt. For the application to work this files must be readable and writable to apache.
For your own application you definitely want to use a better database not to mention provide a way of identifying the different workers.
Next time we will talk about libraries and tools that can help you in your development process.
Remember to follow me on twitter/ subscribe to my feed.
Till next time happy coding!!
by Jacob Chencha