Firebase fan-out structure for news feed - firebase

I have a database with posts, users and other nodes like classic social-media app.
I'm continuing implementing best-practices to my application. And now I want to rewrite my news strip (posts of users, that I follow (like home tab in Instagram)).
I have read some info about fan-out strategy and now I'm confused in how to do it properly.
So, I have 2 opportunities:
Like here: Every time user adds new post, this post with full information will be copied to users-timeline(users news strip)/UID/postId: FULL INFO to all followers of this user. And every edit will edit each mention of this post.
Every time user adds new post, this postID will be copied to user-timeline(users news strip)/UID/postId: true to all followers of this user. And every edit will edit only source post.
Which logic is better with Firebase?

I suggest you using David's East solution. As I see in his post, he uses Firebase denormalization and data flatten, which are the best common practices within Firebase.
I also recommend you reading NoSQL Data Modeling Techniques and Structuring your Firebase Data correctly for a Complex App for a better understanding.
If you have a SQL background, I recommend you seeing also David's East tutorial, The Firebase Database For SQL Developers.

Related

Users following in order to get followed users posts database design and update from app

My use case:
UserA can create post.
Users B,C,D... can follow userA in order to see his posts on their screen.
My design idea:
/users --> registered users
/posts --> collection where users store their posts (in app I have screen that list all posts by date not related to following users so this is what everybody see).
/feed --> when post is created I copy here photo, title, short description and tags this documents has less data than posts.
In user document I have:
/users
-userId
- followers
-userIdB
-userIdC
-userIdD
- followings
Now when UserA create new post:
it is stored in /posts
it is copied with less info in /feed
fetch list of followers and copy with less info in /users/userB...C...D/feed collection.
if userIdE starts to follow userA I copy userA posts to /users/.../userIdE/feed
When I list posts from all I fetch data from /feed
When I list posts from users I follow I fetch from /users/myId/feed
Until this point I think that design is good (I hope).
This is proof of concept that real users will use but I am limited to my app I can't use firebase functions as client doesn't want to start with paid plan.
What could be a problem to make all this data copy to: feed, users/feed from user phone in terms of cost?
I am also scared that somebody can sit and follow/unfollow same user which will make coping data million times.
I believe Firebase functions would be the best way to ensure that the client's server can sanity-check the requests and volume of those requests too.
Instead of copying the actual data, it might be better to just copy references to it.
It will be difficult to understand all constraints from stack overflow post.
Please contact Google support if you are worried about security issues to share details here. And you may have look at this link which may be helpful

Has anyone displayed a Salesforce Dashboard component on WordPress site? If so, how?

I work for a nonprofit which help disabled military veterans. We have all our participants register with us using Salesforce as the repository of their registrations. We have dashboard components in Salesforce Lighting which totals up the number of active participants we have. I would like to display the component on our WordPress site but have never done anything like that before. I was hoping to find someone who has done something like that and offer some direction on how to go about doing it.
I tried looking up WordPress plugins which integrate with Salesforce. Most seem to be geared towards sending registrations back and forth but not displaying information. From a little bit of research, it seems like coding might need to be involved. Maybe doing a REST API with a Post option which will send the data through an HTTP URI? But to my understanding is that it would require WordPress to be an API. I am sure there are gaps in my logic.
I dont have an extensive amount of programing language experience but am willing to learn. I have taken a few Java and JavaScript classes in school.
I have not attempted this yet. I am just looking for feedback and direction.
Few options here, in no specific order...
Do Wordpress users have real Salesforce accounts or is their data simply stored in SF? Ask your Salesforce admin if there's a "customer community" configured (if your SF org is really old he might refer to it as customer portal). Communities offer nice way of exposing SF to poeple who don't need full SF user licenses. Think like collaborating with real SF users on "My Cases", viewing reports & dashboards... But for this you'd really need people logged in to SF so it won't work if you want just something anonymous. Some more info
Another option might be using Sites (Visualforce pages that expose SF data to guest users). Think like displaying a product catalog, FAQ, web-to-lead form or some other generic "contact us" page that's anonymous. So if you have SF developer (or admin with good copy-paste skills) you could use some Visualforce charts. They can be 100% coded (like this) or fed data from a report (like this) so it's simpler for admin to change the report filters or something without really writing code. Not sure if the simple route will work on a Site, there are some old answers that say "No", you might have to try it out. Worst case you'd need Apex code (or JavaScript) to query SF for results and display them. And display that SF Site page as <iframe> in Wordpress.
A slight twist on the Sites option - do you use Chatter (bit like Twitter inside SF)? There's way to take a snapshot of a report when a milestone has been met and post it to chatter ("congrats for hitting X participants"). And embed feeds on Visualforce pages too. Docs
What SF edition you're on (Group/Professional/Enterprise...)? If you have API access to Salesforce you could query the info yourself from Wordpress and display it using whatever charting library's easiest for you (Google Charts, Flot...). There are tons of examples how to connect to SF from PHP (or maybe you could cannibalize a WP plugin). Technically it's one POST message to log in to SF and one GET to run a query (something as simple as SELECT COUNT() FROM Contact WHERE isActive__c = true?)
That'd be more or less everything in terms of pulling data out of Salesforce. I mean if you have API access enabled you can slice & dice it how you want, extract data with raw PHP code or use some middleware but overall idea doesn't change. Write queries yourself or use "Analytics API" to access report results (so your administrator has power to change it without coding)...
So how about pushing? SF could notify you about current participants count. At scheduled intervals or even realtime. That'd be "just" raw data though, you'd have to write visualisation yourself.
Plenty of options here
workflow rules (code-free), sends XML message to specified URL so you'd need a WP page that can "capture" the result. Could be sent on creation of new record or update of existing. Won't give you totals, it'd be data related to that particular record so you'd have to build kind of +1 / -1 counter... Or if you use a report + analytic snapshot (helper object to store report results) and have workflow on that - that could be really close to what's needed.
scheduled apex job to run some queries and send the results to you. Again - you'd need a WP url that can be called from SF
if there's a CometD plugin for Wordpress you should look at Salesforce Streaming API, Platform Events or (newer and even simpler to configure) Change Data Capture. Basically you "subscribe" to a topic (a SF query) and whenever SF data changes and SF decides it'd change the results of the query - it'd push the results to you. It's almost realtime. Too much to write about them, perhaps best if you'd try to click through some trailheads - SF self-paced training courses:
https://trailhead.salesforce.com/en/content/learn/modules/api_basics/api_basics_streaming
https://trailhead.salesforce.com/en/content/learn/modules/change-data-capture
https://trailhead.salesforce.com/en/content/learn/modules/platform_events_basics

Firebase Cloud Firestore strategy for putting old posts in follower’s feeds

I’m building a social networking application that has a follower/following setup, with feeds. Currently my structure is like:
/posts
{postObject}
{postObject}
.
.
.
/users
-{$uid}
/posts
(Contains reference ids to this users posts)
/followers
(Contains reference ids to users)
/following
(Contains reference ids to users)
/feed
(Contains reference ids to user’s posts and posts of the users they follow)
[repeated for each uid]
I currently already have it set up to where, when a user you follow makes a new post, a reference to that post is saved in your feed.
My questions is: when a user follows someone with previous posts, what’s a sensible way to add the FOLLOWED user’s previous posts to the following user’s feed?
My original thought was to (using Cloud Functions) write every post id of the followed user to the following user’s feed, which is a simple implementation, but seems inefficient if the followed user has tens of thousands of posts. Also, considering Firestore charges for reads and writes, it would seem incredibly expensive to perform all those reads and writes (especially if a user follows and then quickly unfollows another user). Admittedly, I’m not even sure this is how the billing for Firestore works.
Any help would be greatly appreciated.

post/send updates or messages to fans(who likes website) not as user

I have simple website for auctioning.I want people who likes my website needs to be informed about any new auctioning. And sending messages or post updates to their news feed or post on their wall when they win the auction. The user can also share the story of a new auction to their friends.
For this Do I need separate canvas app ?
I went through the documentation http://csharpsdk.org/. Also I read official graph api docs.
I thought there will be lists of classes in a namespace and its use. Lists of methods, properties in a class and its uses and explanation for parameters.
I cant find such documentation for facebook c# sdk. In official docs they only have 5 articles in which 3 are [TO-DO].
I cant find what are the classes are there?
what are the purpose of
the particular class or method ?
For informing about new Auctioning and winning news what can be used ?
sending mesages
post on their news feed
post on their wall(or timeline)
I found how to post on behalf of the user. But I need to inform the fans of my website when there is a new auctioning. How to do it?
Winning an auction
About generating user actions on their walls about winning auctions and stuff, you need to look at facebook open graph
For informing about new Auctioning and winning news what can be used ?
#1 sending messages is not possible
Notifying users
For sending notification to users about new auctions, you need to use apprequests
But apprequests are only for canvas apps, apart from this I don't thing you have a chance of notifying the user, unless you store their emails id and notify them.
Hope this helps

Shutterfly Order API .

I found this site
http://www.shutterfly.com/documentation/api_OrderImage.sfly
but there are no examples of actually walking through the whole process. Does anyone have any good documentation on using this API to take a local photo and allow someone to order a print via shutterfly?
I went through these steps:
Sign up for an account
Sign up as a developer
Create an application (I called mine Test). Note the generated Application Id and Shared Secret
The Shutterfly API page has a list of references for various Domain-specific APIs:
Address Book
Album Data
Folder Data
Go To Shutterfly UE
Image Upload
Interactive Sign-in
Image Request
Order
Pricing
Seamless Sign-in
User Data
User Authentication
Each uses RESTful principles. The documentation looks pretty comprehensive to me, if you need some background, here's links for RESTful APIs and ROME you may find useful
There is also an API Explorer section on the same page that allows you to test the methods via a form on their site. For example this form for CRUD operations on the album data.
Based on your comment, for your requirements, you would:
Use the Album GET to list albums, then get the data for a specific album.
Use the Image Get request to retrieve the image data, so your friend can verify the image(s) they want to purchase.
Authenticate the user
Use the Pricing POST request to get the estimated pricing for the image.
User the Order POST to submit the order over https
Update: Found a page describing using a Greasemonkey script which adds Shutterfly print ordering capability to Flickr. This might provide the basis for a solution.
For Reference:
The original link above is a middle step of the Shutterfly Open API ordering procedure.
The whole process goes through a series of steps allowing you to control much more than just pushing photos into somebody's album in Shutterfly.
With this process, your application can actually carry out the entire procedure of:
specifying the images and the sizes and quantities, or other products
calculating shipping, taxes, and totals
paying, and
launching the processing
It also includes the ability to see when the packages will be delivered and arrive.
Thus if you have a solid application for mapping your images onto paper and products, you can pretty much control the entire process.
Once the order is submitted, it will appear on the user's account at Shutterfly who the order was associated with.
Kudos to Shutterfly for making such a powerful tool! It would be great if other printing facilities had similar tools.

Resources