Lesson 4: Extra credit! Create your own hot products, trending products, and/or recommendations system.
Now that you know how to create an event consumer and populate a DynamoDB table, there are all kinds of interesting features you can build.
- Product detail page views
- Category page views
- Purchase events
- ***add specifics here
We know that customers that view the same item multiple times are interested in the product. Create a table and web service that shows the top products that have been frequently viewed (three or more times) by the most unique users.
How would you include time-weighting to your hot products service to ensure that the hot products don't get stale?
Can you create a view that maintains a sorted count of "people who viewed this product also viewed"? How about bought/bought? viewed/bought? frequently viewed/frequently viewed? How would you expose this as a recommendation service that could be used from the product detail page?
If you had 100,000,000 page views a day, how much would your service cost? How could you make it more efficient? How can you trade off pre-computing results into a table vs computing the results on demand from a raw activity table? What are the performance implications?
Did anyone enter more than 3 products as merchant? Did anyone buy lots of their own product?
Using the AWS CLI, you can execute this script to show the ARNs needed:
./show-stream-and-role-arns.sh
It contains the following two commands:
aws iam list-roles | grep Arn | grep $STAGE | sed -n "s/^.*\(arn\:aws\:iam\:\:[0-9]*\:role\/.*StreamWriter\).*/\1/p"
aws kinesis describe-stream --stream-name `aws kinesis list-streams | sed -n "s/^.*\"\(.*\)\".*/\1/p" | grep ${STAGE}Stream` | grep StreamARN | sed -n "s/^.*\(arn\:aws\:kinesis\:.*Stream\).*/\1/p"
- Here we invoke AWS CLI to list all of the roles in the account, using
aws iam list-roles
. We then usegrep
andsed
to filter and shape the output until only the ARN for the StreamWriter role is left. - This two-step command starts by using the AWS command
aws kinesis list-streams
to output the names of all the Kinesis streams in the account, then wegrep
and get our stream name, which we pass to theaws kinesis describe-stream
as thestream-name
parameter. From all of the many properties provided for our stream, wegrep
andsed
to just get the ARN value.
You can run the commands above removing the grep
and sed
portions to explore the output in its raw form and you might notice that the output is in JSON, if you have the AWS CLI configured for that.
Ultimately, grep
and sed
are not very maintainable as a solution and don't take advantage of the structure provided by the output.
It's recommended that you stream the output of these commands to other tools, e.g. JQ.