Cloudstagram is a Realtime Image Sharing Application that runs on Cloud Foundry.
With this app you can:
- Register your own user
- Upload Images including a comment.
- Follow other users
- Like Images
Latest Images: if you are on the latest images tab of Cloudstagram then you will see new images in realtime as they are uploaded by users. As a logged out user you are by default in the latest images view.
User Timeline: Once you log in you will land in your own timeline. This timeline includes your picutres and the pictures of the users that you follow. It's normal that once you log in for the first time you won't see any pictures there.
User Profiles: Each user has it's own profile where you can see information like amount of uploaded images, amount of followers and amount of users followed by the profile owner.
Followers: Following an user means that whenever she uploads a new picture that picture will be pushed in realtime to your browser. That means new pictures of that user will be part of your timeline.
Image Previews: You can preview images by clicking on their thumbnail.
Like Images: You can like an image by double clicking on the picture once you are in preview mode. After the image has been liked you will see that a heart appears bellow the thumbnail with your user name.
node.js: The web application is written in node.js using the express.js web framework.
sock.js: Realtime communication is done by using sock.js.
MongoDB: MongoDB is used to store and server images inside GridFS. Every time a user uploads a picture an imageid
is generated. The images are later references by that imageid
Redis: Main application data is store in Redis including user sessions. The data structure is like this:
- LIST
latest_images
: contains a list ofimageids
. Images are pushed as they become available. - LIST
username:images
: contains a list ofimageids
uploaded byusername
. - INCR
username:image_count
: INT with the amount of images uploaded byusername
. - LIST
username:timeline
: contains a list ofimageids
uploaded byusername
and by the users that she follows. - LIST
imageid:likes
: contains a list ofusernames
that liked the image. - LIST
username:likes
: contains a list ofimageids
liked byusername
. - LIST
username:followers
: contains a list ofusernames
that follow the user. - LIST
username:follows
: contains a list ofusernames
followed by the user. - INCR
username:followers_count
: amount of users that followusername
. - INCR
username:follows_count
: amount of users that followed byusername
.
RabbitMQ: RabbitMQ is used for image post processing and for realtime notifications broadcasting.
Every time a user uploads an image the image is stored into MongoDB. If that operation succeeds then a message is sent to the cloudstagram-new-image
exchange with the following image metadata:
var fileData = {
userid: username,
filename: filename,
comment: comment,
uploaded: ISODateString(new Date()),
mime: mimeType
}
That message is sent to the following queues:
add_image_to_user_queue
: The consumers attached to this queue will register the image in Redis. For example the image will be lpushed to the listusername:timeline
. Then it republishes the message to the following exchange:cloudstagram-broadcast-newimage
.new_image_queue
: In this case the image will be pushed to thelatest_images
list in Redis.image_to_followers_queue
: This consumer does two things. First adds the image to the user followers.
The consumers of add_image_to_user_queue
will publish a message to the cloudstagram-broadcast-newimage
exchange. That exchange is used to then broadcast the message to the user browsers via sock.js.
In this case to use features of Cloud Foundry like multiple instances we have a fanout
exchange and then many anonymous queues (one on each instance). Then from every instance we broadcast the changes to the users connected to it via sock.js. Keep in mind that those changes might have happened in possibly a different instance.
sockjs_broadcast_to_uploader
: This consumer notifies the uploader that her picture is ready, this displaying it in the browser.sockjs_broadcast_to_anonusers
: This consumer pushes the image to all the non logged in users. In this way they will see that activity is happening in realtime in the site.sockjs_broadcast_to_followers_consumer
: This consumer will push the image to the user followers browsers.
The app requires that you bind the following services:
- MongoDB
- Redis
- RabbitMQ
To push the app to Cloud Foundry type:
cf push
This project is by no means affiliated with Instagram.
See LICENSE.md