Wednesday, January 04, 2012

Mobile Application Architecture, Part 3

[Note: So it's taken me a long time to get this third part out. I changed jobs in the middle of writing all of this, and there's a lot to learn at the new gig. Also in case you are wondering, this is heavily based on my experiences working on eBay Mobile for Android and Bump for Android. Both apps use an event driven architecture in places, or at least they did while I was working on them. What follows is not the secret sauce from either application, but some good things that were common to both along with some ideas for improving on the patterns.]

This is the third post in a series on the architecture of mobile applications. In the first post we looked at the classical architecture of mobile apps that evolved from web apps. In the second post we looked at event driven architecture and when it should be used. Now we're going to dive a little deeper into event driven architectures and in particular talk about some of the significant design decisions that must be made and the pitfalls that need to be avoided.

So you say you want an event driven architecture? I'll assume you've done your homework and aren't just doing this to because it seems like the cool thing to do. I'll assume that it really fits your application. One of the first things that you will realize as you get started is that event driven architecture does not exempt you from many important aspects. Security is a great example. You must figure out how you will authenticate with your server and how to secure any sensitive information that you send over the wire. Just because you are no longer in the world of HTTP and HTTPS does not mean that you get to send over people's credit card numbers in plain text. It's not any harder to sniff your bits and chances are that you are just as vulnerable to things like man-in-the-middle attacks. So go read up on things like TCP headers and TLS.

Once the basics are in place, you can think more about the architecture of your application. Your servers are going to be sending events to your application. So what is going to receive them? Do you have each UI (controller, Activity, etc.) receive them? How about something that is more long-lived. The most important thing to remember is that whatever receives events generally has to be able to deal with any kind of event. You can never assume that just because your controller only cares about some small set of events that those will be the only events that it ever receives. Thus you probably need to have an event receiver whose lifecyle extends beyond that of any given screen in your application and can handle any and all events. Now keep in mind that it will often delegate events to other components in your application, so no need to worry about this global receiver being stuffed with knowledge of your app. On Android you could use a Service for this or even a subclass of Application. You could also create some other singleton object that is tied to your application's lifecycle.

Now you might ask does this really need to be a singleton? Not necessarily. However I think that in many (most?) circumstances that a singleton will simplify things for you. What happens to those events that are not needed by the UI? Such events probably mutate some internal state of your application. If that internal state is transient, then it probably makes sense for there to be only one copy of it. If it is persistent... 

Inevitably there will be some events coming in from your server that you do care about at the UI level. These things will probably be "second-hand", i.e. the events will have been received by the longer-lived object we talked about above. Now you need to deal with how to get these events to the UI. The most accepted way to do this is to use an Observer pattern. You define an interface for an object that cares about a certain event (or certain set of related events potentially.) Then the object registers itself with the central receiver. When a new event comes in from the server, the central receiver examines it and decides on who to delegate it to.

I must add a few words of caution here. For each event you can easily wind up with a class for the event's data structure, an interface for the observer, and an implementation of the observer. The last of these things is often handled by having the Activity/Fragment/controller implement the interface, or by using an anonymous inner class to implement it. In any case, you wind up with multiple types being defined for each event. So if you have many types of events that your server will push to your application then you can end up with an explosion of code. Android developers should consider using Handlers and Messages as a leaner, more de-coupled solution. The big downside is that you may windup doing manual type checking and casting. This can be avoided by late binding, i.e. keep the data from the server raw as long as possible and do the parsing after the dispatch to the observer.

Finally I will close this long series of posts with a brief word about server side technologies. This post in particular has focussed on how to write your mobile/client applications with an event driven architecture. There is a flip-side to this and that is how to implement an event driven architecture on your server. Just like in our classical architectures, most servers are dominated by HTTP. That is not only the default interface into them, but it is at the heart of the server's architecture. A connection is a short-lived, usually stateless object. There is generally a one-to-one mapping of HTTP requests to either threads or processes. This is a poor fit for event driven architectures where a connection is extremely long lived. It only dies when the client app dies or explicitly closes it for some reason.

Fortunately there are numerous server side technologies that do not use the request-per-thread/process model. Certainly the most hyped one of these is Node.js. The Internet is chock full of benchmarks showing how Node's non-blocking out-scales Apache, Nginx, etc. However there are numerous other event driven app servers in Python, Java, Ruby, etc. Personally I have a bias towards my ex-colleague Jamie Turner's Diesel framework. The point is that there are many choices on the server and I expect that you will see many more moving forward.

27 comments:

Android app developers said...

This is one of the progressive post.I like your blog quality.Great work.

Vani said...
This comment has been removed by the author.
Anonymous said...

CUSTOMERS ARE MOVING TO MOBILE. YOU FEELING LEFT BEHIND?
You must have magento mobile apps, right away! Because this is the best way to interact and convert sales from mobile users (PROVED)
Go Magento mobile apps to convert sales way better!

SimiCart is a solution that helps Magento Merchants build mobile shopping apps.

Magento merchants: Our solution is specially designed for Magento platform so you can get all the best features of Magento to apps. If you use a solution for every platform you're missing many good things.

Mobile shopping apps: You will have apps that are coded separately and specifically for iPhone and android.
Your customers can search and download your shopping apps from Google Play and Apple stores. And again, such tailored apps will bring the best user experience!

Unknown said...

Good work…unique site and interesting too… keep it up…looking forward for more updates.Good luck to all of you and thanks so much for your hard-work.
asi legal bangalore, asi legal,asi legal cochin,Shahul hameed

muthu said...


Learn about other Apache projects that are part of the Hadoop ecosystem, including Pig, Hive, HBase, ZooKeeper, Oozie, Sqoop, Flume, among others. Big Data University provides separate courses on these other projects, but we recommend you start here.

Bigdata training in Chennai OMR

Wondermouse Technologies said...

WonderMouse Technology is a Digital marketing company in delhi. We market brands on the web & make sure that you get bang for your buck by SEO, SEM, PPC, SMO, Email Marketing, etc. Internet business is the present and eventual fate of overall exchange. WonderMouse Technology is the pioneer in making Ecommerce a smooth ordeal and top website designing company in Delhi knows it great. The platforms are designed specifically to enhance the consumer panorama of corporate websites. We offer customized and affordable best seo services in india which are designed to the needs, desires and budget of our clients.

meldaresearch said...

It is important for cultural studies coursework writing service students to seek Cultural Studies Writing Services from a reputable cultural studies assignment writing service provider for their cultural studies research paper services.

joshnanlabs said...

High Quality Undetectable Counterfeit Bank Notes for sale.
Legit Counterfeit Money. These counterfeits bank notes for sale pass the UV lights and pen tests and are fit to be used anywhere. We are 100% legit and we have all proves to our claims.
For more information contact us on:
WhatsApp: +1 (213)-761-4617
Website: legit counterfeit money for sale
Telegram: joshnan_labs
High quality fake counterfeit money

legit counterfeit Canadian Dollars for sale
high quality fake euros for sale
high quality fake dollars for sale
legit counterfeit GBP for sale
quick tips to make money now
buy legit counterfeit money online
Buy high quality undetectable counterfeit online

This is very good and legit
best quality counterfeit money in the deep web

youtubecomactivate said...

Amazing Post, I really like your post. If any YouTube users need help regarding youtube.com/activate then they can contact us.

jordan said...

Thanks for shearing such a nice article.your writing skill are impressive.Free astrology predictions from top astrologers in India as per your Birth Chart. astrology Prediction life report utilizes your birth chart to see what your future life looks like. The birth chart can reveal so many things about you,Talk to astrologer on call or chat, and get the benefits of free astrology services and products with more than 30 years of experiences astrologer online.

Gemini horoscope 2021
Taurus Horoscope 2021
Aries Horoscope 2021
Talk To Astrologer
Aaj ka Rashifal
Online Astrologer

jordan said...

Thank you for sharing nice article.Astroswamig is the top most astrology prediction portal here you can get live astrology prediction you can ask question about your past present and future or get remedies of your problems.

Talk To Astrologer
Aaj ka Rashifal
Online Astrologer
Free kundli Prediction

@dskastrology said...

Thank you for sharing beautiful content. In case you want to read article in hindi. Then visit below link
DsK Astrology - Most Authentic Website for online astrology services & products
DsK Astrology - Whatsapp Services
DsK Astrology - Talk to Good Astrologer

@dskastrology said...

Thank you for sharing beautiful content. In case you want to read article in hindi. Then visit below link
DsK Astrology - Most Authentic Website for online astrology services & products
DsK Astrology - Whatsapp Services
DsK Astrology - Talk to Good Astrologer

DsK Astrology said...

Thank you for sharing beautiful content. In case you want to read article based on life science, Astrology. Then visit below link
DsK Astrology
DsK Astrology - Most Authentic Website for online astrology services & products
Online Whatsapp Services
Expert Astrologer Online
Job or Business, which is good for you
Manik ratan
Moti Ratan
Moonga Ratan
Panna ratan
Safed pukhraj
Neelam ratan
Rahu gochar
Ketu gochar
Guru gochar
Sani gochar
Surya gochar

Unknown said...

bitcoin private key recovery



In this days that bitcoin is becoming more and more worldwide, is better to secure your bitcoins .
Bitcoin private key finder , this tool will help you to find your lost private key if you cannot access your bitcoin
account.Non-spendable private key finder, if you have huge amount of bitcoins in your wallet that you are looking for the
private key to make them spendable, then this our software will help you .Blockchain private key generator.
Bitcoin recovery tool online.
https://rb.gy/qx0xum
https://cutt.ly/VElDWif
https://zeep.ly/zNvjc
https://bom.to/NoKri4
https://writeablog.net/m18yomb34y
https://is.gd/J3k8Ic
WhatsApp +1(512) 537-3985
https://www.bitcoinprivatekeytool.com/
bitcoin private key crack

Unknown said...

Buy counterfeit money online




Do we earn money to live or vice versa? Sometimes, hard work and minimal wages seem to create a never-ending vicious cycle.
At this point, many people start considering buy counterfeit money online as a possible solution.Best counterfeit banknotes
for sale.The Internet has a wide range of websites offering fake money. However, it’s an extremely delicate subject that requires
a reliable supplier.100% undetectable counterfeit money .Thus, if this is your first time searching for
counterfeit banknotes, you have to be cautious. High quality counterfeit money for sale.https://bit.ly/3Ch2Tmr
To foster the security of your shopping for fake money,Counterfeit Company is the best counterfeit producer online.
https://www.counterfeitcompany.com/
https://is.gd/VXufKX
https://rb.gy/wb6fti
https://zeep.ly/kcMt4
https://rb.gy/qx0xum
+1(234) 386-3720
https://cutt.ly/WElDk0U

Karl Moriss said...

Forex Robot For Sale(High Frequency Forex Trading)
This forex Robot is for traders who wants to avoid the stress of going through all the hardwork of technical and fundamental analysis of trading. Our heiken-ashi trader is not like any other heiken ashi robot that is sold in the market because it manages and hedges your loosing trades for you by closing all trades at an equilibrium price.
You can also set the time you want the forex robot to start trading(for example during the London session) and set the robot to close all trades at the end of the period whether profitable or not.
The Forex Robot is best on forex major currency pairs such as; EURUSD, USDCHF, USDCAD, USDJPY, AUDUSD, GBPUSD, GBPJPY and other minor currency pairs such as; GBPAUD, EURAUD, EURCAD, GBPCAD, GBPNZD, EURJPY, CADJPY, AUDJPY.
66 Hayes street, San Francisco, CA94102, USA
Website: https://www.buyforexeaonline.com/ (secured)
Weblink: https://www.buyforexeaonline.com/product/heiken-ashi-impulse-forex-robot/
Facebook page: https://web.facebook.com/forexexpertadvisorforsale/
WhatsApp: +1(234)517-1674
Phone number: +1(234)517-1674
Email: info@buyforexeaonline.com


Thomas Alex said...


The best Bitcoin private key hack online tool
https://smartprivatekeyhack.com
Bitcoin private key hack online

James Bond said...


We cover a broad-band of buyers’ purchase ability as undetectable fake banknotes supply is
concerned. Bulk and retail unbeatable prices on quality Euro, Great British Pounds,
USA dollars, Canadian and Australian dollars, and more other major currencies.
buy counterfeit dollars online and
best quality counterfeit pounds for sale
first class fake banknotes for sale
Bitcoin private key generator software

Cooper said...

Top-notch counterfeit offers a vast experience in the counterfeit money industry,
Bulk and retail unbeatable prices on quality Euro, Great British Pounds,
USA dollars, Canadian and Australian dollars, and more other major currencies.
Grade A counterfeit banknotes for sale and
Top-Notch counterfeit banknotes
Buy SSD Chemical solution

kelly anna said...



Welcome to Caluanie Muelear Metal Crushing, a leading, United Sates based manufacturer and supplier of Caluanie Muelear Oxidize. Committed to bringing you the highest quality products at the most competitive prices, we are here to simplify your business and life.We are the leading suppliers of Caluanie Muelear Oxidize in the USA. Best quality offer Caluanie Muelear Oxidize at a cheaper price. Also, provide reliable & safe delivery of Caluanie Muelear Oxidize in USA, UK & worldwide. Caluanie Muelear Oxidize is one of the most useful Caluanie derivatives. Caluanie Muelear Oxidize can be used in Caluanie Foundation, Caluanie Oil & Caluanie Crude as a base impurity. Caluanie Muelear Oxidize is used as a base impurity in making other chemical products like refinery processes and it’s also used for medicinal purposes. Caluanie Muelear Oxidize is a chemical substance with the formula (C15H23O2)3, occurring as an impurity in many types of natural oil. It has been isolated from fossil fuels including coal and petroleum. It is used as a reagent to prepare other derivatives of Caluanie esters, such as methyl 3-methyloxepanone carboxylate.

https://caluaniemuelearmetalcrushing.com/

https://caluaniemuelearmetalcrushing.com/blogs/

https://caluaniemuelearmetalcrushing.com/product/buy-caluanie-muelear-oxidize-online/

https://caluaniemuelearmetalcrushing.com/caluanie-muelear-manufacturer/

https://caluaniemuelearmetalcrushing.com/buy-caluanie-muelear-oxidize-for-metal-crushing/

https://caluaniemuelearmetalcrushing.com/caluanie-muelear-oxidize-for-sale-usa/

jackpringle said...

If you have lost your digital wallet, the first
thing to do is to make sure that you’re
on a computer that is connected to the internet.
bitcoin private key finder software online
Blockchain private key generator
Generate private key from bitcoin address online
website: www.smartprivatekeyhack.com
Email: info@smartprivatekeyhack.com
WhatsApp: +1 (646) 926-0214
Telegram: @Tonybright77

Anonymous said...


Best Bitcoin private key generator online 2022 at your disposal
The person who holds the private key fully controls the coins in that wallet.
For this reason, you should keep it secret. And if you really want to generate
Best Bitcoin private key generator online 2022 at your disposal
https://smartprivatekeyhack.com

Cooper said...

High-Quality Counterfeit Canadian dollars For Sale

Buy undetectable counterfeit money USA, Buy 100% undetectable counterfeit money,
We carry the most undetectable and quality counterfeit money for sale
just for you,
Here is your chance to be a millionaire. buy counterfeit money
online, buy fake 20s
our money is perfectly reproduced, Indistinguishable to the eye and to
the touch.
We are sending in various sizes, packed and hidden. All our notes
carry all the
holograms and water marks and pass the light detector test. Buy 100%
undetectable
counterfeit money.
Contact us today
Phone/Whatsapp: +1 (862) 904-0644
Email : info@popularbanknotes.com
Website : www.popularbanknotes.com
Web Link: https://popularbanknotes.com
Product link: https://popularbanknotes.com/product.php?id=56

logesh said...

Thank you for your post. This is superb information. It is amazing and great to visit your site.
ibm full form in india |
ssb ka full form |
what is the full form of dp |
full form of brics |
gnm nursing full form |
full form of bce |
full form of php |
bhim full form |
nota full form in india |
apec full form |

kelly anna said...

We are the leading suppliers of Caluanie Muelear Oxidize in the USA.
Best quality offer Caluanie Muelear Oxidize at a cheaper price.
Also, provide reliable & safe delivery of Caluanie Muelear Oxidize in
USA, UK & worldwide. Caluanie Muelear Oxidize is one of the most useful Caluanie derivatives.
Caluanie Muelear Oxidize can be used in Caluanie Foundation,
Caluanie Oil & Caluanie Crude as a base impurity.
https://popularbanknotes.com
https://caluaniemuelearmetalcrushing.com
https://smartprivatekeyhack.com
https://topnotchcounterfeit.com
https://www.flymedishop.com

Buy Ammonium Chloride Online said...

https://chemglobalexport.com/buy-ammonium-chloride-online/
Buy Ammonium Chloride Online


AMMONIUM CHLORIDE .Dry cell. used as electrolyte in zinc-carbon batteries.
2.Metalwork.as a flux in preparing metals to be tin coated, galvanized or soldered.
3.Other applications. Used to work on oil wells with clay swelling problems. Other uses include in hair shampoo, in the glue that bonds plywood, and in cleaning products. In hair shampoo, it is used as a thickening agent in ammonium-based surfactant systems, such as ammonium lauryl sulfate. Ammonium chlorides used in the textile and leather industry in dyeing , tanning, textile printing and to luster cotton.