Your SlideShare is downloading. ×
0
Server Connect To API / 3rd Service Pattern
Caesar Chi @clonncd
Node.js 與多方服務串接實務
Monday, June 23, 14
@clonncd
Monday, June 23, 14
Monday, June 23, 14
https://github.com/nodejs-tw/nodejs-wiki-book
Monday, June 23, 14
Monday, June 23, 14
Structure
Clients
Server
Monday, June 23, 14
That means we thought done with
something in Node.js
But actually we did nothing special.
Monday, June 23, 14
Monday, June 23, 14
Request of
As a Front end Server
Monday, June 23, 14
Structure
front Server
Services
secret information cache
send Request
Monday, June 23, 14
WWW are APIs
When Node.js has Request
Monday, June 23, 14
Structure
front Server
Services
send Request
...
...
Monday, June 23, 14
But When
Service requirement
Grows Up
Monday, June 23, 14
Structure
front Server
Internal
server
send Request
...
...
Too Much Code To Handle
Monday, June 23, 14
Service Definition
• Front server can be flexible to connect
• Support Restful API for internal connect
• Same Router rule f...
Server Definenation
• Front server can be flexible to connect
• Support Restful API for internal connect
• Same Router rule ...
app3
app2
app1
app4
Routers as apps, auto route
Monday, June 23, 14
app3
app2
app1
app4
Every developers can handle by themselves
Monday, June 23, 14
Make connect easy,
A tiny distribution server
Monday, June 23, 14
Face Response Issue ...
Monday, June 23, 14
Wait ...Wait ...Wait ...
https://www.flickr.com/photos/tormodspictures/
Monday, June 23, 14
伺服器反應很慢
http://chinese.engadget.com/2014/06/21/facebook-android-update-africa/
Monday, June 23, 14
Let’s refactoring code
Monday, June 23, 14
Monday, June 23, 14
Response back as soon as posible
Monday, June 23, 14
Heavy processing or request, put late
Monday, June 23, 14
Response as short as posible
https://www.flickr.com/photos/calliope/
Monday, June 23, 14
what can NOT be late
• real time date, have to be light (geo, data)
• robust data, we could not avoid (but save in
cached,...
What can late
• log data writing
• data saving (not for real time response)
• data caching
Monday, June 23, 14
Response First, Process Later
Tips
Monday, June 23, 14
Too many callback event in waiting queue
https://www.flickr.com/photos/peter_curb/14318113011/sizes/c/in/photostream/
Monda...
WARNNING, It Cause High CPU Usage
https://www.flickr.com/photos/peter_curb/14318113011/sizes/c/in/photostream/
Monday, June...
We put process in
Task Queue.
http://learnboost.github.io/kue/
Monday, June 23, 14
Save process, prarams in Task Queue
Monday, June 23, 14
Monday, June 23, 14
Set callback event when things done
Monday, June 23, 14
Send request to 3rd party library / API / URL
Monday, June 23, 14
Feedback to Server or Storage
trigger callback event to Server
Monday, June 23, 14
Monday, June 23, 14
How feedback to clients, when task queue process
task / jobs done, how could we notify clients?
How about Client?
Monday, ...
Time meet
http://socket.io/
or
Socket
Monday, June 23, 14
Client and Server connect via a Tunnel
Monday, June 23, 14
With handshake
Monday, June 23, 14
Structure
Clients
Server
Server push
Monday, June 23, 14
Structure
Clients
Server
Server push
From single way to double ways
Monday, June 23, 14
Structure
Clients
Server
Server push
From single way to double ways
JSON
Ads
Habit
Monday, June 23, 14
Server push, that means
• Ajax mode changed
• Browser can do more things
• User request is getting more
• Server has to af...
Let’s integrate with
Socket.io / Socket and
Task Queue
Monday, June 23, 14
Feedback to Server or Storage
Monday, June 23, 14
Return data to User in a few minutes
Monday, June 23, 14
Return data to User in a few seconds
Monday, June 23, 14
Increase User Experience
Not Make Them Wait
Monday, June 23, 14
Monday, June 23, 14
Cache Layer
Monday, June 23, 14
Storage Layer
Monday, June 23, 14
Part of access
Monday, June 23, 14
Part of heavy access
Monday, June 23, 14
Not finished yet
Monday, June 23, 14
Monday, June 23, 14
http://letsnode.com/example-of-what-node-is-really-good-at
Monday, June 23, 14
http://mortarnpistol.com/2011/12/16/big-rigs-over-the-road-racing/
Monday, June 23, 14
Monday, June 23, 14
Monday, June 23, 14
Rules
• Make events as light as posible
• Divide things to tiny
• Heavy process throw to another way
• Monitor app.js afte...
https://www.facebook.com/groups/node.js.tw/
https://www.facebook.com/NodeJS.tw
https://github.com/nodejs-tw
http://nodejs....
https://github.com/nodejs-tw/nodejs-book-beginner-guide
Monday, June 23, 14
@clonncd
Monday, June 23, 14
Upcoming SlideShare
Loading in...5
×

Server Connect To API / 3rd Service Pattern

300

Published on

when node.js as a middle server and connect to other servers, what should you notice? what do you have to ready after building a node.js process?

We discuss the infrastructures and node.js processing that we have to know.

Published in: Technology

Transcript of "Server Connect To API / 3rd Service Pattern"

  1. 1. Server Connect To API / 3rd Service Pattern Caesar Chi @clonncd Node.js 與多方服務串接實務 Monday, June 23, 14
  2. 2. @clonncd Monday, June 23, 14
  3. 3. Monday, June 23, 14
  4. 4. https://github.com/nodejs-tw/nodejs-wiki-book Monday, June 23, 14
  5. 5. Monday, June 23, 14
  6. 6. Structure Clients Server Monday, June 23, 14
  7. 7. That means we thought done with something in Node.js But actually we did nothing special. Monday, June 23, 14
  8. 8. Monday, June 23, 14
  9. 9. Request of As a Front end Server Monday, June 23, 14
  10. 10. Structure front Server Services secret information cache send Request Monday, June 23, 14
  11. 11. WWW are APIs When Node.js has Request Monday, June 23, 14
  12. 12. Structure front Server Services send Request ... ... Monday, June 23, 14
  13. 13. But When Service requirement Grows Up Monday, June 23, 14
  14. 14. Structure front Server Internal server send Request ... ... Too Much Code To Handle Monday, June 23, 14
  15. 15. Service Definition • Front server can be flexible to connect • Support Restful API for internal connect • Same Router rule for client • Modules install / uninstall be easy • Light way feedback data Monday, June 23, 14
  16. 16. Server Definenation • Front server can be flexible to connect • Support Restful API for internal connect • Same Router rule for client • Modules install / uninstall be easy • Light way feedback data Service as a module, feature as a apps https://github.com/clonn/module-loader Tips Monday, June 23, 14
  17. 17. app3 app2 app1 app4 Routers as apps, auto route Monday, June 23, 14
  18. 18. app3 app2 app1 app4 Every developers can handle by themselves Monday, June 23, 14
  19. 19. Make connect easy, A tiny distribution server Monday, June 23, 14
  20. 20. Face Response Issue ... Monday, June 23, 14
  21. 21. Wait ...Wait ...Wait ... https://www.flickr.com/photos/tormodspictures/ Monday, June 23, 14
  22. 22. 伺服器反應很慢 http://chinese.engadget.com/2014/06/21/facebook-android-update-africa/ Monday, June 23, 14
  23. 23. Let’s refactoring code Monday, June 23, 14
  24. 24. Monday, June 23, 14
  25. 25. Response back as soon as posible Monday, June 23, 14
  26. 26. Heavy processing or request, put late Monday, June 23, 14
  27. 27. Response as short as posible https://www.flickr.com/photos/calliope/ Monday, June 23, 14
  28. 28. what can NOT be late • real time date, have to be light (geo, data) • robust data, we could not avoid (but save in cached, redis and process them later) Monday, June 23, 14
  29. 29. What can late • log data writing • data saving (not for real time response) • data caching Monday, June 23, 14
  30. 30. Response First, Process Later Tips Monday, June 23, 14
  31. 31. Too many callback event in waiting queue https://www.flickr.com/photos/peter_curb/14318113011/sizes/c/in/photostream/ Monday, June 23, 14
  32. 32. WARNNING, It Cause High CPU Usage https://www.flickr.com/photos/peter_curb/14318113011/sizes/c/in/photostream/ Monday, June 23, 14
  33. 33. We put process in Task Queue. http://learnboost.github.io/kue/ Monday, June 23, 14
  34. 34. Save process, prarams in Task Queue Monday, June 23, 14
  35. 35. Monday, June 23, 14
  36. 36. Set callback event when things done Monday, June 23, 14
  37. 37. Send request to 3rd party library / API / URL Monday, June 23, 14
  38. 38. Feedback to Server or Storage trigger callback event to Server Monday, June 23, 14
  39. 39. Monday, June 23, 14
  40. 40. How feedback to clients, when task queue process task / jobs done, how could we notify clients? How about Client? Monday, June 23, 14
  41. 41. Time meet http://socket.io/ or Socket Monday, June 23, 14
  42. 42. Client and Server connect via a Tunnel Monday, June 23, 14
  43. 43. With handshake Monday, June 23, 14
  44. 44. Structure Clients Server Server push Monday, June 23, 14
  45. 45. Structure Clients Server Server push From single way to double ways Monday, June 23, 14
  46. 46. Structure Clients Server Server push From single way to double ways JSON Ads Habit Monday, June 23, 14
  47. 47. Server push, that means • Ajax mode changed • Browser can do more things • User request is getting more • Server has to afford more currency • Server has opportunity feedback data Monday, June 23, 14
  48. 48. Let’s integrate with Socket.io / Socket and Task Queue Monday, June 23, 14
  49. 49. Feedback to Server or Storage Monday, June 23, 14
  50. 50. Return data to User in a few minutes Monday, June 23, 14
  51. 51. Return data to User in a few seconds Monday, June 23, 14
  52. 52. Increase User Experience Not Make Them Wait Monday, June 23, 14
  53. 53. Monday, June 23, 14
  54. 54. Cache Layer Monday, June 23, 14
  55. 55. Storage Layer Monday, June 23, 14
  56. 56. Part of access Monday, June 23, 14
  57. 57. Part of heavy access Monday, June 23, 14
  58. 58. Not finished yet Monday, June 23, 14
  59. 59. Monday, June 23, 14
  60. 60. http://letsnode.com/example-of-what-node-is-really-good-at Monday, June 23, 14
  61. 61. http://mortarnpistol.com/2011/12/16/big-rigs-over-the-road-racing/ Monday, June 23, 14
  62. 62. Monday, June 23, 14
  63. 63. Monday, June 23, 14
  64. 64. Rules • Make events as light as posible • Divide things to tiny • Heavy process throw to another way • Monitor app.js after done • Figure out bottlenecks • Decrease users idle / waiting time as posible Monday, June 23, 14
  65. 65. https://www.facebook.com/groups/node.js.tw/ https://www.facebook.com/NodeJS.tw https://github.com/nodejs-tw http://nodejs.tw/ http://2014.jsdc.tw/ Monday, June 23, 14
  66. 66. https://github.com/nodejs-tw/nodejs-book-beginner-guide Monday, June 23, 14
  67. 67. @clonncd Monday, June 23, 14
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×