0

I am building a mobile app using Django Rest Framework, Flutter, and MongoDB. In that app users can view posts posted by other users. In my Django app, I don't have any notification model (and honestly don't really know how to use that either!). In Django, I have created endpoints to create posts

@api_view(['POST'])
def createPost(request):
   code/logic...

, and to retrieve posts

class blogsViewSet(ModelViewSet):
    queryset = Posts.objects.all()
    serializer_class = PostSerializer
    pagination_class = pagination.CustomPagination
    
    def list(self, request, *args, **kwargs):
        uid = request.META.get('HTTP_DATA')
        context = {"user": uid}
        queryset = Posts.objects.all().order_by('postID')
        paginatedResult = self.paginate_queryset(queryset)
        serializer = self.get_serializer(paginatedResult, many=True, context= context)
        return Response(serializer.data)

Now in my app, lets say I have two users: User A, and User B. now if both of them are using the app at the same time and user A creates a new post, I want user B to be notified and showed that new post immediately, without the user B having to reload the page himself/herself.

Now my question is, can I achieve this by using Django channel only, or do I have to use Redis (or any similar service). If yes, then how?

Thanks!

1 Answers1

0

First things first: this is a complex topic. So no copy-paste solution here ‍♂️ There are many options you have, I've resumed several that I like:

  1. Django Channels
  2. Standalone microservice with Websockets (my choice!)
  3. FCM data messages (Firebase Cloud Messaging)

Websockets are simple and very useful in terms of bi-directional communication between clients and servers. If your app's features list grows it will be possible that you will need additional events in your app. WS will help you to scale.

Redis is key-value storage that's used for caching or storages purposes, as a backend of queues, etc. Yep, Django Channels using Redis in the backend, but this could be confusing that Redis is made for WebSockets =) It's not

Take a look at the WebSockets they will help you many times in your developer career.

fanni
  • 1,149
  • 8
  • 11